diff --git a/problems/0019.删除链表的倒数第N个节点.md b/problems/0019.删除链表的倒数第N个节点.md index b0641b5f..4e4474ca 100644 --- a/problems/0019.删除链表的倒数第N个节点.md +++ b/problems/0019.删除链表的倒数第N个节点.md @@ -129,10 +129,10 @@ class Solution: head_dummy.next = head slow, fast = head_dummy, head_dummy - while(n!=0): #fast先往前走n步 + while(n>=0): #fast先往前走n+1步 fast = fast.next n -= 1 - while(fast.next!=None): + while(fast!=None): slow = slow.next fast = fast.next #fast 走到结尾后,slow的下一个节点为倒数第N个节点 diff --git a/problems/0059.螺旋矩阵II.md b/problems/0059.螺旋矩阵II.md index d9a656b9..b4dad9c3 100644 --- a/problems/0059.螺旋矩阵II.md +++ b/problems/0059.螺旋矩阵II.md @@ -117,6 +117,9 @@ public: }; ``` +* 时间复杂度 O(n^2): 模拟遍历二维矩阵的时间 +* 空间复杂度 O(1) + ## 类似题目 * 54.螺旋矩阵 diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md index 2437582c..63525b03 100644 --- a/problems/0455.分发饼干.md +++ b/problems/0455.分发饼干.md @@ -219,19 +219,17 @@ func findContentChildren(g []int, s []int) int { ### Rust ```rust -pub fn find_content_children(children: Vec, cookie: Vec) -> i32 { - let mut children = children; - let mut cookies = cookie; +pub fn find_content_children(mut children: Vec, mut cookie: Vec) -> i32 { children.sort(); cookies.sort(); - let (mut child, mut cookie) = (0usize, 0usize); + let (mut child, mut cookie) = (0, 0); while child < children.len() && cookie < cookies.len() { // 优先选择最小饼干喂饱孩子 if children[child] <= cookies[cookie] { child += 1; } - cookie += 1 + cookie += 1; } child as i32 } diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md index a02bf7a2..2d5525ba 100644 --- a/problems/0704.二分查找.md +++ b/problems/0704.二分查找.md @@ -86,6 +86,9 @@ public: }; ``` +* 时间复杂度:O(log n) +* 空间复杂度:O(1) + ### 二分法第二种写法 @@ -124,6 +127,9 @@ public: } }; ``` +* 时间复杂度:O(log n) +* 空间复杂度:O(1) + ## 总结 diff --git a/problems/前序/ACM模式如何构建二叉树.md b/problems/前序/ACM模式如何构建二叉树.md index 42bf7af0..b6446403 100644 --- a/problems/前序/ACM模式如何构建二叉树.md +++ b/problems/前序/ACM模式如何构建二叉树.md @@ -305,11 +305,12 @@ def construct_binary_tree(nums: []) -> TreeNode: Tree.append(node) if i == 0: root = node + # 直接判断2*i+2