07 2021 档案
摘要:时间复杂度: 最好:nlog n 最坏:n*n 平均:nlog n 空间复杂度:log n 稳定性:不稳定 递归实现 def quick_sort(arr, first, last): if first >= last: return pivot = partition2(arr, first, l
阅读全文
摘要:还是算法4上的代码通俗易懂,看了下之前自己写的代码,一大坨,看得人晕晕乎乎的,所以照着书上的思路写了一遍 时间复杂度: 最好:O(nlog n) 最坏:O(n*n) 平均:O(nlog n) 空间复杂度:O(n) 稳定性:稳定 自顶向下递归实现 def merge_sort(arr, first,
阅读全文
摘要:在极客时间买了个python课程,巩固和加强下python能力。想边看边做笔记,需要每节课一个markdown文件,发现每次都手动去拷贝创建文件很麻烦,所以想直接一次性都创建完。下面是创建步骤。 1. 选中元素,鼠标右键Inspect,查看Html,找一下元素特征。如下,发现课程列表都是同一个Css
阅读全文
摘要:def find_middle(self): if not self._head or self._head.next is None: return self._head fast, slow = self._head, self._head fast = fast.next while fast
阅读全文
摘要:def merge_list(self, l1, l2): if l1 and l2: p1, p2 = l1, l2 fakeHead = ListNode(None) cur = fakeHead while p1 and p2: if p1.val <= p2.val: cur.next =
阅读全文
摘要:# 删除链表倒数第n个节点。假设n大于0 def remove_nth_from_end(head): fast = head count = 0 while fast and count < n: fast = fast._next count += 1 if not fast and count
阅读全文
摘要:为啥一定会相遇呢,可以看这个:为什么用快慢指针找链表的环,快指针和慢指针一定会相遇? 代码: def has_cycle(self): fast, low = self._head, self._head while fast and fast.next: low = low.next fast =
阅读全文
摘要:递归实现 1. 代码 # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # 返回ListNode def Revers
阅读全文

浙公网安备 33010602011771号