![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
晨打水水水
这个作者很懒,什么都没留下…
展开
-
Leetcode-19.删除链表的倒数第N个节点(3种方法)-(1)循环(2)递归迭代——回溯计数(3)双指针/快慢指针
Method 1:思路解析:扫描2遍-一遍数长度,一遍删除节点for循环/while循环class Solution: def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: root = ListNode(0) root.next = head #扫描一遍,算长度 a, length = head, 0 while a:...原创 2021-11-23 16:51:21 · 218 阅读 · 0 评论 -
leetcode算法入门-第5天(双指针)
19.删除链表的倒数第N个结点# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode原创 2021-10-22 23:29:04 · 87 阅读 · 0 评论 -
leetcode算法入门14天-第4天(双指针)
344.反转字符串class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ for i in range(len(s)//2): s[i],s[len(s)-1-i]=s[len(s)-1-i],s[i]思路.原创 2021-10-20 19:16:48 · 151 阅读 · 0 评论 -
python常见错误总结
1. 'str' object does not support item assignment原因:python字符串是一种不可变对象,意味着只读不写。想要改变可以把字符串变成数组,修改后再便会字符串。原创 2021-10-20 18:57:45 · 1432 阅读 · 0 评论 -
leetcode递归21、24
21.合并2个有序列表题目:将两个升序链表合并为一个新的升序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。有循环过程时可用递归递归要注意3点:终止条件 递归调用过程 要考虑1、2的顺序class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: if not l1: return l2 #终止条件 if not...原创 2021-10-06 16:18:44 · 74 阅读 · 0 评论