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 81ca79a2e2..4418c62dc4 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: **这个代码就很简洁了,但隐藏了很多逻辑,条理不清晰,而且递归三部曲,在这里完全体现不出来。** -**所以建议大家做题的时候,一定要想清楚逻辑,每一步做什么。把道题目所有情况想到位,相应的代码写出来之后,再去追求简洁代码的效果。** +**所以建议大家做题的时候,一定要想清楚逻辑,每一步做什么。把题目所有情况想到位,相应的代码写出来之后,再去追求简洁代码的效果。** ## 迭代法 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 29ef093375..41a1ede256 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" @@ -365,6 +365,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: 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] ```

AltStyle によって変換されたページ (->オリジナル) /