From d2dc3002903847d97f34707353da8bfe711953f2 Mon Sep 17 00:00:00 2001 From: suichenglixin <52021245+suichenglixin@users.noreply.github.com> Date: Thu, 13 May 2021 18:14:58 +0800 Subject: [PATCH] first commit --- ...10\345\271\266\345\214\272\351\227\264.md" | 30 ++++++++++++- ...14\345\214\205\347\211\210\346\234\254.md" | 18 +++++++- ...11\346\220\234\347\264\242\346\240\221.md" | 15 ++++++- ...00\345\244\247\346\267\261\345\272\246.md" | 14 +++++- ...40\344\272\214\345\217\211\346\240\221.md" | 43 ++++++++++++++++++- ...11\346\220\234\347\264\242\346\240\221.md" | 22 +++++++++- ...41\344\272\214\345\217\211\346\240\221.md" | 25 ++++++++++- ...00\345\260\217\346\267\261\345\272\246.md" | 14 ++++++ ...57\345\276\204\346\200\273\345\222\214.md" | 20 ++++++++- ...\344\275\263\346\227\266\346\234\272II.md" | 20 ++++++++- ...4.\345\212\240\346\262\271\347\253\231.md" | 23 +++++++++- ...06\345\217\221\347\263\226\346\236\234.md" | 30 ++++++++++++- ...25\350\257\215\346\213\206\345\210\206.md" | 18 +++++++- ...73\350\275\254\351\223\276\350\241\250.md" | 20 ++++++++- ...04\345\255\220\346\225\260\347\273\204.md" | 21 ++++++++- ...345\220\210\346\200\273\345\222\214III.md" | 25 ++++++++++- ...02\347\202\271\344\270\252\346\225\260.md" | 13 +++++- ...54\344\272\214\345\217\211\346\240\221.md" | 20 ++++++++- ...54\345\205\261\347\245\226\345\205\210.md" | 21 +++++++-- ...54\345\205\261\347\245\226\345\205\210.md" | 17 +++++++- ...15\345\274\202\344\275\215\350\257\215.md" | 21 ++++++++- ...00\346\234\211\350\267\257\345\276\204.md" | 35 ++++++++++++++- ...66\345\255\220\344\271\213\345\222\214.md" | 17 +++++++- ...15\345\273\272\351\230\237\345\210\227.md" | 25 ++++++++++- ...15\345\217\240\345\214\272\351\227\264.md" | 29 ++++++++++++- ...55\347\232\204\350\212\202\347\202\271.md" | 29 ++++++++++++- ...25\347\210\206\346\260\224\347\220\203.md" | 29 ++++++++++++- ...06\345\217\221\351\245\274\345\271\262.md" | 22 ++++++++-- ...36\345\255\220\345\272\217\345\210\227.md" | 28 +++++++++++- ...4.\347\233\256\346\240\207\345\222\214.md" | 21 ++++++++- ...55\347\232\204\344\274\227\346\225\260.md" | 42 +++++++++++++++++- ...13\350\247\222\347\232\204\345\200\274.md" | 24 ++++++++++- ...17\347\273\235\345\257\271\345\267\256.md" | 21 ++++++++- ...72\347\264\257\345\212\240\346\240\221.md" | 18 +++++++- ...66\344\272\214\345\217\211\346\240\221.md" | 16 ++++++- ...47\344\272\214\345\217\211\346\240\221.md" | 26 ++++++++++- ...11\346\220\234\347\264\242\346\240\221.md" | 25 ++++++++++- ...55\347\232\204\346\220\234\347\264\242.md" | 13 +++++- ...22\345\205\245\346\223\215\344\275\234.md" | 28 +++++++++++- ...53\346\211\213\347\273\255\350\264\271.md" | 18 +++++++- ...36\347\232\204\346\225\260\345\255\227.md" | 20 ++++++++- ...27\346\257\215\345\214\272\351\227\264.md" | 23 +++++++++- ...54\346\260\264\346\211\276\351\233\266.md" | 30 ++++++++++++- ...47\344\272\214\345\217\211\346\240\221.md" | 29 ++++++++++++- ...04\346\225\260\347\273\204\345\222\214.md" | 26 ++++++++++- 45 files changed, 984 insertions(+), 60 deletions(-) diff --git "a/problems/0056.\345\220\210\345\271\266\345\214\272\351\227\264.md" "b/problems/0056.\345\220\210\345\271\266\345\214\272\351\227\264.md" index f939325f9e..e84a1634a3 100644 --- "a/problems/0056.\345\220\210\345\271\266\345\214\272\351\227\264.md" +++ "b/problems/0056.\345\220\210\345\271\266\345\214\272\351\227\264.md" @@ -137,7 +137,35 @@ public: Java: +```java +class Solution { + public int[][] merge(int[][] intervals) { + List res = new LinkedList<>(); + Arrays.sort(intervals, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if (o1[0] != o2[0]) { + return Integer.compare(o1[0],o2[0]); + } else { + return Integer.compare(o1[1],o2[1]); + } + } + }); + int start = intervals[0][0]; + for (int i = 1; i < intervals.length; i++) { + if (intervals[i][0] > intervals[i - 1][1]) { + res.add(new int[]{start, intervals[i - 1][1]}); + start = intervals[i][0]; + } else { + intervals[i][1] = Math.max(intervals[i][1], intervals[i - 1][1]); + } + } + res.add(new int[]{start, intervals[intervals.length - 1][1]}); + return res.toArray(new int[res.size()][]); + } +} +``` Python: @@ -151,4 +179,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" "b/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" index beda45d529..d6b1245083 100644 --- "a/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" +++ "b/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" @@ -127,7 +127,23 @@ public: Java: +```java +class Solution { + public int climbStairs(int n) { + int[] dp = new int[n + 1]; + int[] weight = {1,2}; + dp[0] = 1; + + for (int i = 0; i <= n; i++) { + for (int j = 0; j < weight.length; j++) { + if (i >= weight[j]) dp[i] += dp[i - weight[j]]; + } + } + return dp[n]; + } +} +``` Python: @@ -141,4 +157,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" "b/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" index baa3f435ef..524d6a07ae 100644 --- "a/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" +++ "b/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" @@ -254,6 +254,19 @@ public: Java: +```java +class Solution { + public boolean isValidBST(TreeNode root) { + return isValidBST_2(root, Long.MIN_VALUE, Long.MAX_VALUE); + } + + public boolean isValidBST_2 (TreeNode root, long lo, long hi) { + if (root == null) return true; + if (root.val >= hi || root.val <= lo) return false; + return isValidBST_2(root.left,lo,root.val) && isValidBST_2(root.right,root.val,hi); + } +} +``` Python: @@ -268,4 +281,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" "b/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" index 814beb55bc..bf6d40a3fb 100644 --- "a/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" +++ "b/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" @@ -231,6 +231,18 @@ public: Java: +```java +class Solution { + public int maxDepth(TreeNode root) { + if (root == null) { + return 0; + } + int leftdeep = maxDepth(root.left); + int rightdeep = maxDepth(root.right); + return 1+Math.max(leftdeep,rightdeep); + } +} +``` Python: @@ -245,4 +257,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.md" "b/problems/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.md" index f1f30b7174..907f91f66f 100644 --- "a/problems/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.md" @@ -582,6 +582,47 @@ tree2 的前序遍历是[1 2 3], 后序遍历是[3 2 1]。 Java: +```java +class Solution { + public TreeNode buildTree(int[] inorder, int[] postorder) { + if (inorder.length == 0 || postorder.length == 0) return null; + return buildTree(inorder, postorder,0,inorder.length,0,postorder.length); + } + + private TreeNode buildTree(int[] inorder, int[] postorder, int infrom, int into, + int postfrom, int postto) { + if (postfrom == postto) return null; + + int rootValue = postorder[postto - 1]; + TreeNode root = new TreeNode(rootValue); + + if (postfrom + 1 == postto) return root; + + int splitNum = postto - 1; + for (int i = infrom; i < into; i++) { + if (inorder[i] == rootValue) { + splitNum = i; + break; + } + } + + int inLeftBegin = infrom; + int inLeftEnd = splitNum; + int inRightBegin = splitNum + 1; + int inRightEnd = into; + + int postLeftBegin = postfrom; + int postLeftEnd = postLeftBegin + (splitNum - inLeftBegin); + int postRightBegin = postLeftBegin + (splitNum - inLeftBegin); + int postRightEnd = postto - 1; + + root.left = buildTree(inorder,postorder,inLeftBegin,inLeftEnd,postLeftBegin,postLeftEnd); + root.right = buildTree(inorder,postorder,inRightBegin,inRightEnd,postRightBegin,postRightEnd); + + return root; + } +} +``` Python: @@ -596,4 +637,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" "b/problems/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" index 12d47e6a01..952dc68797 100644 --- "a/problems/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" +++ "b/problems/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" @@ -209,6 +209,26 @@ public: Java: +```java +class Solution { + public TreeNode sortedArrayToBST(int[] nums) { + return sortArr(nums,0,nums.length); + } + + private TreeNode sortArr(int[] nums, int lo, int hi) { + if (lo == hi) return null; + int rootIdx = (lo + hi)/2; + + int rootValue = nums[rootIdx]; + TreeNode root = new TreeNode(rootValue); + + root.left = sortArr(nums,lo,rootIdx); + root.right = sortArr(nums,rootIdx+1,hi); + + return root; + } +} +``` Python: @@ -223,4 +243,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.md" "b/problems/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.md" index 5d55910c66..b8a373fd9d 100644 --- "a/problems/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.md" @@ -355,6 +355,29 @@ public: Java: +```java +class Solution { + boolean flag = true; + public boolean isBalanced(TreeNode root) { + high(root); + return flag; + } + + private int high (TreeNode root) { + if (root == null) return 0; + if (flag) { + int left = high(root.left); + int right = high(root.right); + + if (Math.abs(left - right) > 1) flag = false; + + return Math.max(left,right) + 1; + } else { + return -1; + } + } +} +``` Python: @@ -369,4 +392,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.md" "b/problems/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.md" index 6c6b4632d4..4f79b334ac 100644 --- "a/problems/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.md" +++ "b/problems/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.md" @@ -194,6 +194,20 @@ public: Java: +```java +class Solution { + public int minDepth(TreeNode root) { + if (root == null) return 0; + int leftDeep = minDepth(root.left); + int rightDeep = minDepth(root.right); + + if (root.left == null && root.right != null) return 1+rightDeep; + if (root.left != null && root.right == null) return 1+leftDeep; + + return Math.min(leftDeep,rightDeep)+1; + } +} +``` Python: diff --git "a/problems/0112.\350\267\257\345\276\204\346\200\273\345\222\214.md" "b/problems/0112.\350\267\257\345\276\204\346\200\273\345\222\214.md" index 718a2f5bd3..deee84cfc7 100644 --- "a/problems/0112.\350\267\257\345\276\204\346\200\273\345\222\214.md" +++ "b/problems/0112.\350\267\257\345\276\204\346\200\273\345\222\214.md" @@ -305,6 +305,24 @@ public: Java: +```java +class Solution { + private boolean flag = false; + public boolean hasPathSum(TreeNode root, int targetSum) { + has_2(root,targetSum); + return flag; + } + + public void has_2 (TreeNode root, int count) { + if (root == null) return; + if (root.left == null && root.right == null && count == root.val) { + flag = true; + } + if (root.left != null) has_2(root.left,count - root.val); + if (root.right != null) has_2(root.right,count - root.val); + } +} +``` Python: @@ -387,4 +405,4 @@ let pathSum = function (root, targetSum) { * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II.md" "b/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II.md" index 1a9b4f7f6c..0e770972a5 100644 --- "a/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II.md" +++ "b/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II.md" @@ -135,7 +135,23 @@ public: Java: - +```java +class Solution { + public int maxProfit(int[] prices) { + int sum = 0; + int profit = 0; + int buy = prices[0]; + for (int i = 1; i < prices.length; i++) { + profit = prices[i] - buy; + if (profit > 0) { + sum += profit; + } + buy = prices[i]; + } + return sum; + } +} +``` Python: @@ -149,4 +165,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0134.\345\212\240\346\262\271\347\253\231.md" "b/problems/0134.\345\212\240\346\262\271\347\253\231.md" index 9c72e84d9c..393e46279f 100644 --- "a/problems/0134.\345\212\240\346\262\271\347\253\231.md" +++ "b/problems/0134.\345\212\240\346\262\271\347\253\231.md" @@ -199,7 +199,28 @@ public: Java: +```java +class Solution { + public int canCompleteCircuit(int[] gas, int[] cost) { + int sum = 0; + int min = 0; + for (int i = 0; i < gas.length; i++) { + sum += (gas[i] - cost[i]); + min = Math.min(sum, min); + } + + if (sum < 0) return -1; + if (min >= 0) return 0; + + for (int i = gas.length - 1; i > 0; i--) { + min += (gas[i] - cost[i]); + if (min >= 0) return i; + } + return -1; + } +} +``` Python: @@ -213,4 +234,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0135.\345\210\206\345\217\221\347\263\226\346\236\234.md" "b/problems/0135.\345\210\206\345\217\221\347\263\226\346\236\234.md" index 0595cff663..fedf876534 100644 --- "a/problems/0135.\345\210\206\345\217\221\347\263\226\346\236\234.md" +++ "b/problems/0135.\345\210\206\345\217\221\347\263\226\346\236\234.md" @@ -130,7 +130,35 @@ public: Java: +```java +class Solution { + public int candy(int[] ratings) { + int[] candy = new int[ratings.length]; + for (int i = 0; i < candy.length; i++) { + candy[i] = 1; + } + for (int i = 1; i < ratings.length; i++) { + if (ratings[i] > ratings[i - 1]) { + candy[i] = candy[i - 1] + 1; + } + } + + for (int i = ratings.length - 2; i >= 0; i--) { + if (ratings[i] > ratings[i + 1]) { + candy[i] = Math.max(candy[i],candy[i + 1] + 1); + } + } + + int count = 0; + for (int i = 0; i < candy.length; i++) { + count += candy[i]; + } + + return count; + } +} +``` Python: @@ -144,4 +172,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" "b/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" index ec9965651e..c6d8e43b35 100644 --- "a/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" +++ "b/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" @@ -232,7 +232,23 @@ public: Java: +```java +class Solution { + public boolean wordBreak(String s, List wordDict) { + boolean[] valid = new boolean[s.length() + 1]; + valid[0] = true; + for (int i = 1; i <= s.length(); i++) { + for (int j = 0; j < i; j++) { + if (wordDict.contains(s.substring(j,i)) && valid[j]) { + valid[i] = true; + } + } + } + return valid[s.length()]; + } +} +``` Python: @@ -246,4 +262,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" "b/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" index b465cdf9d9..1bff0b7426 100644 --- "a/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" +++ "b/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" @@ -102,6 +102,24 @@ public: Java: +```java +class Solution { + public ListNode reverseList(ListNode head) { + if (head == null || head.next == null) return head; + ListNode last = head; + ListNode cur = head.next; + head.next = null; + while (cur.next != null) { + ListNode tmp = cur.next; + cur.next = last; + last = cur; + cur = tmp; + } + cur.next = last; + return cur; + } +} +``` Python: @@ -116,4 +134,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.md" "b/problems/0209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.md" index 1b00c4e360..53e03077ac 100644 --- "a/problems/0209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.md" +++ "b/problems/0209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.md" @@ -148,7 +148,24 @@ class Solution: Java: - +```java +class Solution { + public int minSubArrayLen(int target, int[] nums) { + Integer size = Integer.MAX_VALUE; + int from = 0; + int to = 0; + int sum = 0; + while (to < nums.length) { + sum += nums[to++]; + while (sum >= target) { + size = Math.min(size,to - from); + sum -= nums[from++]; + } + } + return size == Integer.MAX_VALUE ? 0 : size; + } +} +``` Python: @@ -177,4 +194,4 @@ var minSubArrayLen = (target, nums) => { * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0216.\347\273\204\345\220\210\346\200\273\345\222\214III.md" "b/problems/0216.\347\273\204\345\220\210\346\200\273\345\222\214III.md" index 11a8eb8f1e..351b98c9d9 100644 --- "a/problems/0216.\347\273\204\345\220\210\346\200\273\345\222\214III.md" +++ "b/problems/0216.\347\273\204\345\220\210\346\200\273\345\222\214III.md" @@ -227,7 +227,30 @@ public: Java: +```java +class Solution { + private List path = new ArrayList<>(); + private List> res = new ArrayList<>(); + public List> combinationSum3(int k, int n) { + backtracking(k, n, 1); + return res; + } + + private void backtracking (int k, int count, int start) { + if (count == 0 && k == 0) { + res.add(new ArrayList<>(path)); + return; + } + for (int i = start; i <= 9; i++) { + path.add(i); + backtracking(k - 1, count - i, i + 1); + path.remove(path.size() - 1); + } + } + +} +``` Python: @@ -241,4 +264,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.md" "b/problems/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.md" index 367fa717b9..991d21f38c 100644 --- "a/problems/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.md" +++ "b/problems/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.md" @@ -194,7 +194,18 @@ public: Java: +```java +class Solution { + public int countNodes(TreeNode root) { + if (root == null) return 0; + + int leftnum = countNodes(root.left); + int rightnum = countNodes(root.right); + return leftnum + rightnum + 1; + } +} +``` Python: @@ -208,4 +219,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.md" "b/problems/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.md" index afc1f14484..2fa6dc065a 100644 --- "a/problems/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.md" @@ -203,7 +203,25 @@ public: Java: +```java +class Solution { + public TreeNode invertTree(TreeNode root) { + invert(root); + return root; + } + private static void invert (TreeNode root) { + if (root == null) return; + + invert(root.left); + TreeNode t = root.left; + root.left = root.right; + root.right = t; + + invert(root.left); + } +} +``` Python: @@ -217,4 +235,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0235.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" "b/problems/0235.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" index cb9de8b0ed..93642de5d5 100644 --- "a/problems/0235.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" +++ "b/problems/0235.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" @@ -29,7 +29,7 @@ 输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4 输出: 2 解释: 节点 2 和节点 4 的最近公共祖先是 2, 因为根据定义最近公共祖先节点可以为节点本身。 -  + 说明: @@ -229,7 +229,22 @@ public: Java: - +```java +class Solution { + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + while (true) { + if (root.val > p.val && root.val > q.val) { + root = root.left; + } else if (root.val < p.val && root.val < q.val) { + root = root.right; + } else { + break; + } + } + return root; + } +} +``` Python: @@ -243,4 +258,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0236.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" "b/problems/0236.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" index 17096d489b..9a8c3948fa 100644 --- "a/problems/0236.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" +++ "b/problems/0236.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.md" @@ -223,7 +223,20 @@ public: Java: - +```java +class Solution { + TreeNode pre; + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || root.val == p.val ||root.val == q.val) return root; + TreeNode left = lowestCommonAncestor(root.left,p,q); + TreeNode right = lowestCommonAncestor(root.right,p,q); + if (left != null && right != null) return root; + else if (left == null && right != null) return right; + else if (left != null && right == null) return left; + else return null; + } +} +``` Python: @@ -237,4 +250,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.md" "b/problems/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.md" index be553c5aa1..49798ccea4 100644 --- "a/problems/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.md" +++ "b/problems/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.md" @@ -85,7 +85,26 @@ public: Java: +```java +class Solution { + public boolean isAnagram(String s, String t) { + int[] strMap = new int[123]; + for (int i = 0; i < s.length(); i++) { + strMap[s.charAt(i) + 0]++; + } + + for (int i = 0; i < t.length(); i++) { + strMap[t.charAt(i) + 0]--; + } + + for (int i = 90; i < 123; i++) { + if (strMap[i] != 0) return false; + } + return true; + } +} +``` Python: @@ -120,4 +139,4 @@ func isAnagram(s string, t string) bool { * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.md" "b/problems/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.md" index a104b27c08..f6515a78d5 100644 --- "a/problems/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.md" +++ "b/problems/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.md" @@ -280,8 +280,39 @@ public: ## 其他语言版本 - Java: +```java +class Solution { + public List binaryTreePaths(TreeNode root) { + LinkedList stack = new LinkedList<>(); + List list = new LinkedList<>(); + TreePaths(root,stack,list); + return list; + } + + private static void TreePaths (TreeNode root, LinkedList path, List res) { + path.add(root); + if (root.left == null && root.right == null) { + StringBuilder sb = new StringBuilder(); + for (TreeNode n : path) { + sb.append(n.val); + sb.append("->"); + } + sb.delete(sb.length()-2,sb.length()); + res.add(sb.toString()); + return; + } + if (root.left != null) { + TreePaths(root.left, path, res); + path.removeLast(); + } + if (root.right != null) { + TreePaths(root.right, path, res); + path.removeLast(); + } + } +} +``` Python: @@ -296,4 +327,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0404.\345\267\246\345\217\266\345\255\220\344\271\213\345\222\214.md" "b/problems/0404.\345\267\246\345\217\266\345\255\220\344\271\213\345\222\214.md" index 8ff2b32069..16c8fa6716 100644 --- "a/problems/0404.\345\267\246\345\217\266\345\255\220\344\271\213\345\222\214.md" +++ "b/problems/0404.\345\267\246\345\217\266\345\255\220\344\271\213\345\222\214.md" @@ -161,7 +161,20 @@ public: Java: - +```java +class Solution { + public int sumOfLeftLeaves(TreeNode root) { + if (root == null) return 0; + int sum = 0; + if (root.left != null && root.left.left == null && root.left.right == null) { + sum = root.left.val; + } + int left = sumOfLeftLeaves(root.left); + int right = sumOfLeftLeaves(root.right); + return left + right + sum; + } +} +``` Python: @@ -175,4 +188,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0406.\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.md" "b/problems/0406.\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.md" index b5260a8c19..2ef0a2fdd2 100644 --- "a/problems/0406.\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.md" +++ "b/problems/0406.\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.md" @@ -185,7 +185,30 @@ public: Java: +```java +class Solution { + public int[][] reconstructQueue(int[][] people) { + Arrays.sort(people, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if (o1[0] != o2[0]) { + return Integer.compare(o2[0],o1[0]); + } else { + return Integer.compare(o1[1],o2[1]); + } + } + }); + LinkedList que = new LinkedList<>(); + + for (int[] p : people) { + que.add(p[1],p); + } + + return que.toArray(new int[people.length][]); + } +} +``` Python: @@ -199,4 +222,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.md" "b/problems/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.md" index 3df496f4e1..4341f3b8a9 100644 --- "a/problems/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.md" +++ "b/problems/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.md" @@ -182,7 +182,34 @@ public: Java: +```java +class Solution { + public int eraseOverlapIntervals(int[][] intervals) { + if (intervals.length < 2) return 0; + Arrays.sort(intervals, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if (o1[0] != o2[0]) { + return Integer.compare(o1[1],o2[1]); + } else { + return Integer.compare(o2[0],o1[0]); + } + } + }); + int count = 0; + int edge = intervals[0][1]; + for (int i = 1; i < intervals.length; i++) { + if (intervals[i][0] < edge) { + count++; + } else { + edge = intervals[i][1]; + } + } + return count; + } +} +``` Python: @@ -196,4 +223,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0450.\345\210\240\351\231\244\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\350\212\202\347\202\271.md" "b/problems/0450.\345\210\240\351\231\244\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\350\212\202\347\202\271.md" index ed0cb9d71e..2670435eff 100644 --- "a/problems/0450.\345\210\240\351\231\244\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\350\212\202\347\202\271.md" +++ "b/problems/0450.\345\210\240\351\231\244\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\350\212\202\347\202\271.md" @@ -251,7 +251,34 @@ public: Java: +```java +class Solution { + public TreeNode deleteNode(TreeNode root, int key) { + root = delete(root,key); + return root; + } + private TreeNode delete(TreeNode root, int key) { + if (root == null) return null; + + if (root.val > key) { + root.left = delete(root.left,key); + } else if (root.val < key) { + root.right = delete(root.right,key); + } else { + if (root.left == null) return root.right; + if (root.right == null) return root.left; + TreeNode tmp = root.right; + while (tmp.left != null) { + tmp = tmp.left; + } + root.val = tmp.val; + root.right = delete(root.right,tmp.val); + } + return root; + } +} +``` Python: @@ -265,4 +292,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" "b/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" index 7372ea929b..f62fb15306 100644 --- "a/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" +++ "b/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" @@ -139,7 +139,32 @@ public: Java: - +```java +class Solution { + public int findMinArrowShots(int[][] points) { + Arrays.sort(points, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if (o1[0] != o2[0]) { + return Integer.compare(o1[0],o2[0]); + } else { + return Integer.compare(o1[0],o2[0]); + } + } + }); + + int count = 1; + for (int i = 1; i < points.length; i++) { + if (points[i][0] > points[i - 1][1]) { + count++; + } else { + points[i][1] = Math.min(points[i][1],points[i - 1][1]); + } + } + return count; + } +} +``` Python: @@ -153,4 +178,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0455.\345\210\206\345\217\221\351\245\274\345\271\262.md" "b/problems/0455.\345\210\206\345\217\221\351\245\274\345\271\262.md" index ca3eba7467..f57a7fa64a 100644 --- "a/problems/0455.\345\210\206\345\217\221\351\245\274\345\271\262.md" +++ "b/problems/0455.\345\210\206\345\217\221\351\245\274\345\271\262.md" @@ -30,7 +30,7 @@ 你有两个孩子和三块小饼干,2个孩子的胃口值分别是1,2。 你拥有的饼干数量和尺寸都足以让所有孩子满足。 所以你应该输出2. -  + 提示: * 1 <= g.length <= 3 * 10^4 @@ -115,7 +115,23 @@ public: Java: - +```java +class Solution { + public int findContentChildren(int[] g, int[] s) { + Arrays.sort(g); + Arrays.sort(s); + int start = 0; + int count = 0; + for (int i = 0; i < s.length && start < g.length; i++) { + if (s[i] >= g[start]) { + start++; + count++; + } + } + return count; + } +} +``` Python: @@ -129,4 +145,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0491.\351\200\222\345\242\236\345\255\220\345\272\217\345\210\227.md" "b/problems/0491.\351\200\222\345\242\236\345\255\220\345\272\217\345\210\227.md" index 5deec0eeff..5e36d6bed4 100644 --- "a/problems/0491.\351\200\222\345\242\236\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/0491.\351\200\222\345\242\236\345\255\220\345\272\217\345\210\227.md" @@ -200,6 +200,32 @@ public: Java: +```java +class Solution { + private List path = new ArrayList<>(); + private List> res = new ArrayList<>(); + public List> findSubsequences(int[] nums) { + backtracking(nums,0); + return res; + } + + private void backtracking (int[] nums, int start) { + if (path.size() > 1) { + res.add(new ArrayList<>(path)); + } + + int[] used = new int[201]; + for (int i = start; i < nums.length; i++) { + if (!path.isEmpty() && nums[i] < path.get(path.size() - 1) || + (used[nums[i] + 100] == 1)) continue; + used[nums[i] + 100] = 1; + path.add(nums[i]); + backtracking(nums, i + 1); + path.remove(path.size() - 1); + } + } +} +``` Python: @@ -214,4 +240,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0494.\347\233\256\346\240\207\345\222\214.md" "b/problems/0494.\347\233\256\346\240\207\345\222\214.md" index 2fb2a5eb1c..1782c88c27 100644 --- "a/problems/0494.\347\233\256\346\240\207\345\222\214.md" +++ "b/problems/0494.\347\233\256\346\240\207\345\222\214.md" @@ -241,7 +241,24 @@ dp[j] += dp[j - nums[i]]; Java: - +```java +class Solution { + public int findTargetSumWays(int[] nums, int target) { + int sum = 0; + for (int i = 0; i < nums.length; i++) sum += nums[i]; + if ((target + sum) % 2 != 0) return 0; + int size = (target + sum) / 2; + int[] dp = new int[size + 1]; + dp[0] = 1; + for (int i = 0; i < nums.length; i++) { + for (int j = size; j >= nums[i]; j--) { + dp[j] += dp[j - nums[i]]; + } + } + return dp[size]; + } +} +``` Python: @@ -255,4 +272,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0501.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\274\227\346\225\260.md" "b/problems/0501.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\274\227\346\225\260.md" index 0e8c0d0e8b..b555692f1c 100644 --- "a/problems/0501.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\274\227\346\225\260.md" +++ "b/problems/0501.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\274\227\346\225\260.md" @@ -344,7 +344,47 @@ public: Java: +```java +class Solution { + private LinkedList list = new LinkedList<>(); + private int currentValue; + private int count; + private int maxCount; + public int[] findMode(TreeNode root) { + count = 0; + maxCount = 0; + currentValue = root.val; + findModeTrl(root); + int[] res = new int[list.size()]; + for (int i = 0; i < res.length; i++) { + res[i] = list.get(i); + } + return res; + } + private void findModeTrl (TreeNode root) { + if (root == null) return; + findModeTrl(root.left); + if (root.val == currentValue) { + count++; + } else { + currentValue = root.val; + count = 1; + } + + if (count == maxCount) { + list.add(root.val); + } else if (count > maxCount) { + maxCount = count; + list.clear(); + list.add(currentValue); + } + + findModeTrl(root.right); + } +} + +``` Python: @@ -358,4 +398,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.md" "b/problems/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.md" index 19c870c367..e3be890590 100644 --- "a/problems/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.md" +++ "b/problems/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.md" @@ -217,7 +217,29 @@ public: Java: +```java +class Solution { + private int Deep = -1; + private int value = 0; + public int findBottomLeftValue(TreeNode root) { + value = root.val; + findLeftValue(root,0); + return value; + } + private void findLeftValue (TreeNode root,int deep) { + if (root == null) return; + if (root.left == null && root.right == null) { + if (deep > Deep) { + value = root.val; + Deep = deep; + } + } + if (root.left != null) findLeftValue(root.left,deep + 1); + if (root.right != null) findLeftValue(root.right,deep + 1); + } +} +``` Python: @@ -231,4 +253,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" "b/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" index d5abc692db..87ed222ed9 100644 --- "a/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" +++ "b/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" @@ -151,7 +151,26 @@ public: Java: +```java +class Solution { + private TreeNode pre = null; + private int res = Integer.MAX_VALUE; + public int getMinimumDifference(TreeNode root) { + getMiniDiff(root); + return res; + } + private void getMiniDiff (TreeNode root) { + if (root == null) return; + getMiniDiff(root.left); + if (pre != null) { + res = Math.min(root.val - pre.val,res); + } + pre = root; + getMiniDiff(root.right); + } +} +``` Python: @@ -165,4 +184,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.md" "b/problems/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.md" index a5f4c43c0d..a44452e2aa 100644 --- "a/problems/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.md" +++ "b/problems/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.md" @@ -173,7 +173,23 @@ public: Java: +```java +class Solution { + private int count = 0; + public TreeNode convertBST(TreeNode root) { + convert(root); + return root; + } + private void convert (TreeNode root) { + if (root == null) return; + convert(root.right); + count += root.val; + root.val = count; + convert(root.left); + } +} +``` Python: @@ -187,4 +203,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.md" "b/problems/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.md" index adc0703bc3..9836f56838 100644 --- "a/problems/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.md" @@ -256,7 +256,19 @@ public: Java: - +```java +class Solution { + public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { + if (root1 == null) return root2; + if (root2 == null) return root1; + + TreeNode newRoot = new TreeNode(root1.val + root2.val); + newRoot.left = mergeTrees(root1.left,root2.left); + newRoot.right = mergeTrees(root1.right,root2.right); + return newRoot; + } +} +``` Python: @@ -270,4 +282,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.md" "b/problems/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.md" index af133e0cdd..ef417078e1 100644 --- "a/problems/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.md" @@ -224,7 +224,31 @@ root->right = traversal(nums, maxValueIndex + 1, right); Java: +```java +class Solution { + public TreeNode constructMaximumBinaryTree(int[] nums) { + if (nums.length == 0) return null; + return constructMaximumBinaryTree(nums,0,nums.length); + } + + private TreeNode constructMaximumBinaryTree(int[] nums, int begin, int end) { + if (begin == end) return null; + int rootValue = nums[begin]; + int index = begin; + for (int i = begin; i < end ; i++) { + if (nums[i] > rootValue) { + rootValue = nums[i]; + index = i; + } + } + TreeNode root = new TreeNode(rootValue); + root.left = constructMaximumBinaryTree(nums, begin,index); + root.right = constructMaximumBinaryTree(nums,index+1,end); + return root; + } +} +``` Python: @@ -238,4 +262,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" "b/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" index 41f684f4a9..442ea8fb76 100644 --- "a/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" +++ "b/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" @@ -242,7 +242,30 @@ public: Java: +```java +class Solution { + public TreeNode trimBST(TreeNode root, int low, int high) { + root = trim(root,low,high); + return root; + } + + private static TreeNode trim(TreeNode root,int low, int high) { + if (root == null ) return null; + if (root.val < low) { + return trim(root.right,low,high); + } + if (root.val > high) { + return trim(root.left,low,high); + } + root.left = trim(root.left,low,high); + root.right = trim(root.right,low,high); + + return root; + } +} + +``` Python: @@ -256,4 +279,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" "b/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" index 5c1cdfdf54..74a8c0730c 100644 --- "a/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" +++ "b/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" @@ -142,7 +142,16 @@ public: Java: - +```java +class Solution { + public TreeNode searchBST(TreeNode root, int val) { + if (root == null) return null; + if (root.val == val) return root; + if (root.val > val) return searchBST(root.left, val); + return searchBST(root.right, val); + } +} +``` Python: @@ -156,4 +165,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.md" "b/problems/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.md" index 760509d9cc..05f5aa027d 100644 --- "a/problems/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.md" +++ "b/problems/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.md" @@ -16,7 +16,7 @@ 注意,可能存在多种有效的插入方式,只要树在插入后仍保持为二叉搜索树即可。 你可以返回任意有效的结果。 ![701.二叉搜索树中的插入操作](https://img-blog.csdnimg.cn/20201019173259554.png) -  + 提示: * 给定的树上的节点数介于 0 和 10^4 之间 @@ -208,6 +208,30 @@ public: Java: +```java +class Solution { + public TreeNode insertIntoBST(TreeNode root, int val) { + if (root == null) return new TreeNode(val); + TreeNode newRoot = root; + TreeNode pre = root; + while (root != null) { + pre = root; + if (root.val > val) { + root = root.left; + } else if (root.val < val) { + root = root.right; + } + } + if (pre.val > val) { + pre.left = new TreeNode(val); + } else { + pre.right = new TreeNode(val); + } + + return newRoot; + } +} +``` Python: @@ -222,4 +246,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.md" "b/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.md" index 92697a6413..86954c1459 100644 --- "a/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.md" +++ "b/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.md" @@ -156,7 +156,23 @@ public: Java: - +```java +class Solution { + public int maxProfit(int[] prices, int fee) { + int buy = prices[0] + fee; + int sum = 0; + for (int p : prices) { + if (p + fee < buy) { + buy = p + fee; + } else if (p > buy){ + sum += p - buy; + buy = p; + } + } + return sum; + } +} +``` Python: diff --git "a/problems/0738.\345\215\225\350\260\203\351\200\222\345\242\236\347\232\204\346\225\260\345\255\227.md" "b/problems/0738.\345\215\225\350\260\203\351\200\222\345\242\236\347\232\204\346\225\260\345\255\227.md" index d423d4d646..dc136028a7 100644 --- "a/problems/0738.\345\215\225\350\260\203\351\200\222\345\242\236\347\232\204\346\225\260\345\255\227.md" +++ "b/problems/0738.\345\215\225\350\260\203\351\200\222\345\242\236\347\232\204\346\225\260\345\255\227.md" @@ -125,6 +125,24 @@ public: Java: +```java +class Solution { + public int monotoneIncreasingDigits(int N) { + String[] strings = (N + "").split(""); + int start = strings.length; + for (int i = strings.length - 1; i > 0; i--) { + if (Integer.parseInt(strings[i]) < Integer.parseInt(strings[i - 1])) { + strings[i - 1] = (Integer.parseInt(strings[i - 1]) - 1) + ""; + start = i; + } + } + for (int i = start; i < strings.length; i++) { + strings[i] = "9"; + } + return Integer.parseInt(String.join("",strings)); + } +} +``` Python: @@ -139,4 +157,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.md" "b/problems/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.md" index 1b93edf710..c147428080 100644 --- "a/problems/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.md" +++ "b/problems/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.md" @@ -84,7 +84,28 @@ public: Java: - +```java +class Solution { + public List partitionLabels(String S) { + List list = new LinkedList<>(); + int[] edge = new int[123]; + char[] chars = S.toCharArray(); + for (int i = 0; i < chars.length; i++) { + edge[chars[i] - 0] = i; + } + int idx = 0; + int last = -1; + for (int i = 0; i < chars.length; i++) { + idx = Math.max(idx,edge[chars[i] - 0]); + if (i == idx) { + list.add(i - last); + last = i; + } + } + return list; + } +} +``` Python: diff --git "a/problems/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.md" "b/problems/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.md" index c718b0cd5b..bf8a377641 100644 --- "a/problems/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.md" +++ "b/problems/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.md" @@ -127,7 +127,33 @@ public: Java: - +```java +class Solution { + public boolean lemonadeChange(int[] bills) { + int cash_5 = 0; + int cash_10 = 0; + + for (int i = 0; i < bills.length; i++) { + if (bills[i] == 5) { + cash_5++; + } else if (bills[i] == 10) { + cash_5--; + cash_10++; + } else if (bills[i] == 20) { + if (cash_10 > 0) { + cash_10--; + cash_5--; + } else { + cash_5 -= 3; + } + } + if (cash_5 < 0 || cash_10 < 0) return false; + } + + return true; + } +} +``` Python: @@ -141,4 +167,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/0968.\347\233\221\346\216\247\344\272\214\345\217\211\346\240\221.md" "b/problems/0968.\347\233\221\346\216\247\344\272\214\345\217\211\346\240\221.md" index ab2bd2e55e..e541ba139f 100644 --- "a/problems/0968.\347\233\221\346\216\247\344\272\214\345\217\211\346\240\221.md" +++ "b/problems/0968.\347\233\221\346\216\247\344\272\214\345\217\211\346\240\221.md" @@ -316,6 +316,33 @@ public: Java: +```java +class Solution { + private int count = 0; + public int minCameraCover(TreeNode root) { + if (trval(root) == 0) count++; + return count; + } + + private int trval(TreeNode root) { + if (root == null) return -1; + + int left = trval(root.left); + int right = trval(root.right); + + if (left == 0 || right == 0) { + count++; + return 2; + } + + if (left == 2 || right == 2) { + return 1; + } + + return 0; + } +} +``` Python: @@ -330,4 +357,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file diff --git "a/problems/1005.K\346\254\241\345\217\226\345\217\215\345\220\216\346\234\200\345\244\247\345\214\226\347\232\204\346\225\260\347\273\204\345\222\214.md" "b/problems/1005.K\346\254\241\345\217\226\345\217\215\345\220\216\346\234\200\345\244\247\345\214\226\347\232\204\346\225\260\347\273\204\345\222\214.md" index b2073e1434..1653201e8f 100644 --- "a/problems/1005.K\346\254\241\345\217\226\345\217\215\345\220\216\346\234\200\345\244\247\345\214\226\347\232\204\346\225\260\347\273\204\345\222\214.md" +++ "b/problems/1005.K\346\254\241\345\217\226\345\217\215\345\220\216\346\234\200\345\244\247\345\214\226\347\232\204\346\225\260\347\273\204\345\222\214.md" @@ -29,7 +29,7 @@ 输入:A = [2,-3,-1,5,-4], K = 2 输出:13 解释:选择索引 (1, 4) ,然后 A 变为 [2,3,-1,5,4]。 -  + 提示: * 1 <= A.length <= 10000 @@ -99,7 +99,29 @@ public: Java: +```java +class Solution { + public int largestSumAfterKNegations(int[] A, int K) { + if (A.length == 1) return A[0]; + Arrays.sort(A); + int sum = 0; + int idx = 0; + for (int i = 0; i < K; i++) { + if (i < A.length - 1 && A[idx] < 0) { + A[idx] = -A[idx]; + if (A[idx] >= Math.abs(A[idx + 1])) idx++; + continue; + } + A[idx] = -A[idx]; + } + for (int i = 0; i < A.length; i++) { + sum += A[i]; + } + return sum; + } +} +``` Python: @@ -113,4 +135,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file