随笔分类 - leetcode算法题
摘要:class Solution: def isPalindrome(self, head: ListNode) -> bool: vals = [] current_node = head while current_node is not None: vals.append(current_node
阅读全文
posted @ 2021-09-12 20:19
秋华
摘要:class Solution: def reverseList(self, head: ListNode) -> ListNode: #空链表 if not head: return None #1节点链表 elif not head.next: return head #多节点链表 else: p
阅读全文
posted @ 2021-09-12 20:15
秋华
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def
阅读全文
posted @ 2021-09-12 20:09
秋华
摘要:class Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: a, b = headA, headB while a != b: if a: a = a.next else:
阅读全文
posted @ 2021-09-12 20:06
秋华
摘要:class Solution: # 归并排序 def sortList(self, head: ListNode) -> ListNode: if not head or not head.next: return head left_end = self.find_mid(head) mid =
阅读全文
posted @ 2021-09-12 20:02
秋华
摘要:解题思路思路的话就是打牌呗,看到后面比前面大的,在前面一个一个找,找到了就记录下一张牌,然后当前牌放到前面去,前面的pre放到后面去,结束这一次循环。提前用dummy记录,然后利用pre对dummy第一层的操作可以让dummy一直指向最前面的牌 class Solution: def inserti
阅读全文
posted @ 2021-09-12 19:59
秋华
摘要:1.调库太难了,一些用法比较生僻。不如手写 2.可能面试时候,就是想让手写 3.小建议:(1)head 和 tail是dummy结点。一定要用,不然光check边界就会疯掉(2)类中的函数不是固定的。根据自己的习惯和设计,需要什么功能就写什么功能(3)双向链表中的尽量‘干净’、‘简洁’。本来就是很容
阅读全文
posted @ 2021-09-12 19:58
秋华

浙公网安备 33010602011771号