From 5daf942cd584259762907c1e796ad535d5aa9ce6 Mon Sep 17 00:00:00 2001 From: Lozakaka <102352821+Lozakaka@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:47:54 -0400 Subject: [PATCH 1/3] =?UTF-8?q?Update=200225.=E7=94=A8=E9=98=9F=E5=88=97?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A0=88.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增一個java solution用的是卡哥的邏輯 --- ...27\345\256\236\347\216\260\346\240\210.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git "a/problems/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.md" "b/problems/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.md" index 16b9e47cae..66d807c1b1 100644 --- "a/problems/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.md" +++ "b/problems/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.md" @@ -324,6 +324,43 @@ class MyStack { } } +``` +优化,使用一个 Queue 实现,但用卡哥的逻辑实现 +``` +class MyStack { + Queue queue; + + public MyStack() { + queue = new LinkedList<>(); + } + + public void push(int x) { + queue.add(x); + } + + public int pop() { + rePosition(); + return queue.poll(); + } + + public int top() { + rePosition(); + int result = queue.poll(); + queue.add(result); + return result; + } + + public boolean empty() { + return queue.isEmpty(); + } + + public void rePosition(){ + int size = queue.size(); + size--; + while(size-->0) + queue.add(queue.poll()); + } +} ``` Python: From c5c7dfb7fe0c0e7aa5c2115bed085d417d0726c0 Mon Sep 17 00:00:00 2001 From: zbb Date: Tue, 25 Apr 2023 19:45:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=200101.=E5=AF=B9?= =?UTF-8?q?=E7=A7=B0=E4=BA=8C=E5=8F=89=E6=A0=91.md=20=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E9=94=99=E5=88=AB=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...57\271\347\247\260\344\272\214\345\217\211\346\240\221.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/problems/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.md" "b/problems/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.md" index b75e9ff2da..1594196bc9 100644 --- "a/problems/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.md" @@ -88,7 +88,7 @@ else if (left->val != right->val) return false; // 注意这里我没有 * 比较二叉树外侧是否对称:传入的是左节点的左孩子,右节点的右孩子。 -* 比较内测是否对称,传入左节点的右孩子,右节点的左孩子。 +* 比较内侧是否对称,传入左节点的右孩子,右节点的左孩子。 * 如果左右都对称就返回true ,有一侧不对称就返回false 。 代码如下: @@ -157,7 +157,7 @@ public: **这个代码就很简洁了,但隐藏了很多逻辑,条理不清晰,而且递归三部曲,在这里完全体现不出来。** -**所以建议大家做题的时候,一定要想清楚逻辑,每一步做什么。把道题目所有情况想到位,相应的代码写出来之后,再去追求简洁代码的效果。** +**所以建议大家做题的时候,一定要想清楚逻辑,每一步做什么。把题目所有情况想到位,相应的代码写出来之后,再去追求简洁代码的效果。** ## 迭代法 From 31d2755d18a216384495f25654cd4510c360dadf Mon Sep 17 00:00:00 2001 From: xiaodi007 <334830452@qq.com> Date: Fri, 28 Apr 2023 11:17:08 +0800 Subject: [PATCH 3/3] fix 0343 py code --- .../0343.\346\225\264\346\225\260\346\213\206\345\210\206.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/problems/0343.\346\225\264\346\225\260\346\213\206\345\210\206.md" "b/problems/0343.\346\225\264\346\225\260\346\213\206\345\210\206.md" index c2fbbdde68..812bf67bec 100644 --- "a/problems/0343.\346\225\264\346\225\260\346\213\206\345\210\206.md" +++ "b/problems/0343.\346\225\264\346\225\260\346\213\206\345\210\206.md" @@ -254,7 +254,7 @@ class Solution: # 假设对正整数 i 拆分出的第一个正整数是 j(1 <= j < i),则有以下两种方案: # 1) 将 i 拆分成 j 和 i−j 的和,且 i−j 不再拆分成多个正整数,此时的乘积是 j * (i-j) # 2) 将 i 拆分成 j 和 i−j 的和,且 i−j 继续拆分成多个正整数,此时的乘积是 j * dp[i-j] - for j in range(1, i / 2 + 1): + for j in range(1, i // 2 + 1): dp[i] = max(dp[i], max(j * (i - j), j * dp[i - j])) return dp[n] ```