From c7c3d8febf477054cefd6b243d07dc3cb512ad00 Mon Sep 17 00:00:00 2001 From: ChrisLin Date: Sun, 6 Jun 2021 22:19:11 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A00746.=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E8=8A=B1=E8=B4=B9=E7=88=AC=E6=A5=BCJavaScrip?= =?UTF-8?q?t=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0746.使用最小花费爬楼梯.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index 1e8e8038..4238a389 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -255,7 +255,18 @@ func min(a, b int) int { } ``` - +Javascript: +```Javascript +var minCostClimbingStairs = function(cost) { + const dp = [ cost[0], cost[1] ] + + for (let i = 2; i < cost.length; ++i) { + dp[i] = Math.min(dp[i -1] + cost[i], dp[i - 2] + cost[i]) + } + + return Math.min(dp[cost.length - 1], dp[cost.length - 2]) +}; +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) From 55f48dc2718afa8886fcdc27a616231693b27480 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Mon, 7 Jun 2021 21:14:00 +0800 Subject: [PATCH 02/12] =?UTF-8?q?0860.=E6=9F=A0=E6=AA=AC=E6=B0=B4=E6=89=BE?= =?UTF-8?q?=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index faee2e56..1a5634b5 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -184,7 +184,41 @@ class Solution: Go: +Javascript: +```Javascript +var lemonadeChange = function(bills) { + let fiveCount = 0 + let tenCount = 0 + let twentyCount = 0 + for(let i = 0; i < bills.length; i++) { + let bill = bills[i] + if(bill === 5) { + fiveCount += 1 + } else if (bill === 10) { + if(fiveCount > 0) { + fiveCount -=1 + tenCount += 1 + } else { + return false + } + } else { + if(tenCount > 0 && fiveCount > 0) { + twentyCount += 1 + tenCount -= 1 + fiveCount -= 1 + } else if(fiveCount >= 3) { + twentyCount += 1 + fiveCount -= 3 + } else { + return false + } + } + } + return true +}; + +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) From 622a5e233b9935dd95dc7b1bca8d2afd08b15376 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Mon, 7 Jun 2021 21:14:42 +0800 Subject: [PATCH 03/12] =?UTF-8?q?0860.=E6=9F=A0=E6=AA=AC=E6=B0=B4=E6=89=BE?= =?UTF-8?q?=E9=9B=B6.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index 1a5634b5..a18c008d 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -189,7 +189,6 @@ Javascript: var lemonadeChange = function(bills) { let fiveCount = 0 let tenCount = 0 - let twentyCount = 0 for(let i = 0; i < bills.length; i++) { let bill = bills[i] @@ -204,11 +203,9 @@ var lemonadeChange = function(bills) { } } else { if(tenCount > 0 && fiveCount > 0) { - twentyCount += 1 tenCount -= 1 fiveCount -= 1 } else if(fiveCount >= 3) { - twentyCount += 1 fiveCount -= 3 } else { return false From 216088fe7c0d5192f4128084de9548848283a818 Mon Sep 17 00:00:00 2001 From: haofeng <852172305@qq.com> Date: Mon, 7 Jun 2021 23:17:38 +0800 Subject: [PATCH 04/12] =?UTF-8?q?Update=20=E8=83=8C=E5=8C=85=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E8=83=8C=E5=8C=85.md=20=E6=B7=BB=E5=8A=A0=20python3=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0518.零钱兑换II.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md index 2dee030c..08aff9ac 100644 --- a/problems/0518.零钱兑换II.md +++ b/problems/0518.零钱兑换II.md @@ -33,7 +33,7 @@ 示例 3: 输入: amount = 10, coins = [10] 输出: 1 -  + 注意,你可以假设: * 0 <= amount (总金额) <= 5000 @@ -207,6 +207,21 @@ class Solution { Python: +```python3 +class Solution: + def change(self, amount: int, coins: List[int]) -> int: + dp = [0]*(amount + 1) + dp[0] = 1 + # 遍历物品 + for i in range(len(coins)): + # 遍历背包 + for j in range(coins[i], amount + 1): + dp[j] += dp[j - coins[i]] + return dp[amount] +``` + + + Go: From 484d320502e0756c61396c3beb461fcedd65229a Mon Sep 17 00:00:00 2001 From: LiangDazhu <42199191+LiangDazhu@users.noreply.github.com> Date: Tue, 8 Jun 2021 00:08:38 +0800 Subject: [PATCH 05/12] =?UTF-8?q?Update=200518.=E9=9B=B6=E9=92=B1=E5=85=91?= =?UTF-8?q?=E6=8D=A2II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added python version code --- problems/0518.零钱兑换II.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md index 2dee030c..7ee8818e 100644 --- a/problems/0518.零钱兑换II.md +++ b/problems/0518.零钱兑换II.md @@ -101,7 +101,7 @@ dp[j] (考虑coins[i]的组合总和) 就是所有的dp[j - coins[i]](不 而本题要求凑成总和的组合数,元素之间要求没有顺序。 -所以纯完全背包是能凑成总结就行,不用管怎么凑的。 +所以纯完全背包是能凑成总和就行,不用管怎么凑的。 本题是求凑出来的方案个数,且每个方案个数是为组合数。 @@ -206,7 +206,16 @@ class Solution { ``` Python: - +```python +class Solution: + def change(self, amount: int, coins: List[int]) -> int: + dp = [0] * (amount + 1) + dp[0] = 1 + for i in range(len(coins)): + for j in range(coins[i], amount + 1): + dp[j] += dp[j - coins[i]] + return dp[amount] +``` Go: From 3fd92a4905c67df6fdf4c2238bd8c4f5f03fb595 Mon Sep 17 00:00:00 2001 From: jojoo15 <75017412+jojoo15@users.noreply.github.com> Date: Mon, 7 Jun 2021 20:55:40 +0200 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BC=98=E5=8C=96=200455.=20=E5=88=86?= =?UTF-8?q?=E5=8F=91=E9=A5=BC=E5=B9=B2=20python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 0455. 分发饼干 python3版本 --- problems/0455.分发饼干.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md index ecf7f132..4814d414 100644 --- a/problems/0455.分发饼干.md +++ b/problems/0455.分发饼干.md @@ -134,22 +134,17 @@ class Solution { ``` Python: -```python +```python3 class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: - #先考虑胃口小的孩子 g.sort() s.sort() - i=j=0 - count = 0 - while(i= g[res]: #小饼干先喂饱小胃口 + res += 1 + return res ``` - Go: Javascript: From 881ddb1a551a7c9fe22b75adf159b0f8d768bb61 Mon Sep 17 00:00:00 2001 From: jojoo15 <75017412+jojoo15@users.noreply.github.com> Date: Mon, 7 Jun 2021 23:09:51 +0200 Subject: [PATCH 07/12] =?UTF-8?q?=E4=BC=98=E5=8C=96=200376.=20=E6=91=86?= =?UTF-8?q?=E5=8A=A8=E5=BA=8F=E5=88=97=20python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 0376. 摆动序列 python3版本 --- problems/0376.摆动序列.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md index bbca5ea0..4d283eb0 100644 --- a/problems/0376.摆动序列.md +++ b/problems/0376.摆动序列.md @@ -138,20 +138,16 @@ class Solution { ``` Python: -```python +```python3 class Solution: def wiggleMaxLength(self, nums: List[int]) -> int: - #贪心 求波峰数量 + 波谷数量 - if len(nums)<=1: - return len(nums) - cur, pre = 0,0 #当前一对差值,前一对差值 - count = 1#默认最右边有一个峰值 - for i in range(len(nums)-1): - cur = nums[i+1] - nums[i] - if((cur>0 and pre<=0) or (cur<0 and pre>=0)): - count += 1 - pre = cur - return count + preC,curC,res = 0,0,1 #题目里nums长度大于等于1,当长度为1时,其实到不了for循环里去,所以不用考虑nums长度 + for i in range(len(nums) - 1): + curC = nums[i + 1] - nums[i] + if curC * preC <= 0 and curC !=0: #差值为0时,不算摆动 + res += 1 + preC = curC #如果当前差值和上一个差值为一正一负时,才需要用当前差值替代上一个差值 + return res ``` Go: From 895db79105f33131c5cf90f4db5e121457dbcb16 Mon Sep 17 00:00:00 2001 From: borninfreedom Date: Tue, 8 Jun 2021 09:48:37 +0800 Subject: [PATCH 08/12] =?UTF-8?q?update=20=E4=BA=8C=E5=88=86=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=BA=86python=E5=B7=A6?= =?UTF-8?q?=E9=97=AD=E5=8F=B3=E5=BC=80=E5=8C=BA=E9=97=B4=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=90=8C=E6=97=B6=E5=AF=B9=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=81=9A=E4=BA=86=E4=B8=8B=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0704.二分查找.md | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md index 0442ceaa..931e6e5c 100644 --- a/problems/0704.二分查找.md +++ b/problems/0704.二分查找.md @@ -13,16 +13,21 @@ 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target  ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 - 示例 1: + +``` 输入: nums = [-1,0,3,5,9,12], target = 9 输出: 4 解释: 9 出现在 nums 中并且下标为 4 +``` 示例 2: + +``` 输入: nums = [-1,0,3,5,9,12], target = 2 输出: -1 解释: 2 不存在 nums 中因此返回 -1 +``` 提示: @@ -146,7 +151,7 @@ public: ## 其他语言版本 -Java: +**Java:** (版本一)左闭右闭区间 @@ -192,9 +197,11 @@ class Solution { } ``` -Python: +**Python:** -```python3 +(版本一)左闭右闭区间 + +```python class Solution: def search(self, nums: List[int], target: int) -> int: left, right = 0, len(nums) - 1 @@ -211,8 +218,26 @@ class Solution: return -1 ``` +(版本二)左闭右开区间 -Go: +```python +class Solution: + def search(self, nums: List[int], target: int) -> int: + left,right =0, len(nums) + while left < right: + mid = (left + right) // 2 + if nums[mid] < target: + left = mid+1 + elif nums[mid] > target: + right = mid + else: + return mid + return -1 +``` + + + +**Go:** (版本一)左闭右闭区间 @@ -254,7 +279,7 @@ func search(nums []int, target int) int { } ``` -javaScript +**javaScript:** ```js From 7aad63754097b29ce05a36d8a8c1cfa7b711fb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=A4=E9=9C=B2?= <080301087@163.com> Date: Tue, 8 Jun 2021 10:06:37 +0800 Subject: [PATCH 09/12] =?UTF-8?q?Update=200102.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index c7fdf776..ca24cc8f 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -98,15 +98,13 @@ class Solution: out_list = [] while quene: + length = len(queue) # 这里一定要先求出队列的长度,不能用range(len(queue)),因为queue长度是变化的 in_list = [] - for _ in range(len(quene)): - node = quene.pop(0) - in_list.append(node.val) - if node.left: - quene.append(node.left) - if node.right: - quene.append(node.right) - + for _ in range(length): + curnode = queue.pop(0) #(默认移除列表最后一个元素)这里需要移除队列最头上的那个 + in_list.append(curnode.val) + if curnode.left : queue.append(curnode.left) + if curnode.right: queue.append(curnode.right) out_list.append(in_list) return out_list From d0822ea7eddd5f070dac5a6567c5bcc7e9d858cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=A4=E9=9C=B2?= <080301087@163.com> Date: Tue, 8 Jun 2021 10:24:24 +0800 Subject: [PATCH 10/12] =?UTF-8?q?Update=200102.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index ca24cc8f..89d0dda7 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -98,12 +98,12 @@ class Solution: out_list = [] while quene: - length = len(queue) # 这里一定要先求出队列的长度,不能用range(len(queue)),因为queue长度是变化的 + length = len(queue) # 这里一定要先求出队列的长度,不能用range(len(queue)),因为queue长度是变化的 in_list = [] for _ in range(length): - curnode = queue.pop(0) #(默认移除列表最后一个元素)这里需要移除队列最头上的那个 + curnode = queue.pop(0) # (默认移除列表最后一个元素)这里需要移除队列最头上的那个 in_list.append(curnode.val) - if curnode.left : queue.append(curnode.left) + if curnode.left: queue.append(curnode.left) if curnode.right: queue.append(curnode.right) out_list.append(in_list) From fdb48d991f346b673462fb5b6546c855d0376614 Mon Sep 17 00:00:00 2001 From: lichuanming <1465802096@qq.com> Date: Tue, 8 Jun 2021 10:27:14 +0800 Subject: [PATCH 11/12] =?UTF-8?q?0053=20dp=20java=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0053.最大子序和(动态规划).md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/problems/0053.最大子序和(动态规划).md b/problems/0053.最大子序和(动态规划).md index 3cd687a6..e15f692e 100644 --- a/problems/0053.最大子序和(动态规划).md +++ b/problems/0053.最大子序和(动态规划).md @@ -95,7 +95,32 @@ public: Java: +```java + /** + * 1.dp[i]代表当前下标对应的最大值 + * 2.递推公式 dp[i] = max (dp[i-1]+nums[i],nums[i]) res = max(res,dp[i]) + * 3.初始化 都为 0 + * 4.遍历方向,从前往后 + * 5.举例推导结果。。。 + * + * @param nums + * @return + */ + public static int maxSubArray(int[] nums) { + if (nums.length == 0) { + return 0; + } + int res = nums[0]; + int[] dp = new int[nums.length]; + dp[0] = nums[0]; + for (int i = 1; i < nums.length; i++) { + dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]); + res = res > dp[i] ? res : dp[i]; + } + return res; + } +``` Python: From 5eb21ea5676dd566caa4b2896a4cf73af399879c Mon Sep 17 00:00:00 2001 From: youngyangyang04 <826123027@qq.com> Date: Tue, 8 Jun 2021 15:09:07 +0800 Subject: [PATCH 12/12] Update --- README.md | 5 ++++ problems/0104.二叉树的最大深度.md | 34 ----------------------- problems/0383.赎金信.md | 10 +++---- problems/面试题02.07.链表相交.md | 4 +-- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 58f71049..4fa9100d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@

+

+ + + + # LeetCode 刷题攻略 diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index 5f0fe411..f1a84978 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -193,40 +193,6 @@ public: }; ``` -使用栈来模拟后序遍历依然可以 - -```C++ -class Solution { -public: - int maxDepth(TreeNode* root) { - stack st; - if (root != NULL) st.push(root); - int depth = 0; - int result = 0; - while (!st.empty()) { - TreeNode* node = st.top(); - if (node != NULL) { - st.pop(); - st.push(node); // 中 - st.push(NULL); - depth++; - if (node->right) st.push(node->right); // 右 - if (node->left) st.push(node->left); // 左 - - } else { - st.pop(); - node = st.top(); - st.pop(); - depth--; - } - result = result > depth ? result : depth; - } - return result; - - } -}; -``` - ## 其他语言版本 diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md index 23e2c5fd..2f3c4f4d 100644 --- a/problems/0383.赎金信.md +++ b/problems/0383.赎金信.md @@ -22,13 +22,13 @@ https://leetcode-cn.com/problems/ransom-note/ 你可以假设两个字符串均只含有小写字母。 -canConstruct("a", "b") -> false -canConstruct("aa", "ab") -> false -canConstruct("aa", "aab") -> true +canConstruct("a", "b") -> false +canConstruct("aa", "ab") -> false +canConstruct("aa", "aab") -> true ## 思路 -这道题目和[242.有效的字母异位词](https://mp.weixin.qq.com/s/vM6OszkM6L1Mx2Ralm9Dig)很像,[242.有效的字母异位词](https://mp.weixin.qq.com/s/vM6OszkM6L1Mx2Ralm9Dig)相当于求 字符串a 和 字符串b 是否可以相互组成 ,而这道题目是求 字符串a能否组成字符串b,而不用管字符串b 能不能组成字符串a。 +这道题目和[242.有效的字母异位词](https://mp.weixin.qq.com/s/ffS8jaVFNUWyfn_8T31IdA)很像,[242.有效的字母异位词](https://mp.weixin.qq.com/s/ffS8jaVFNUWyfn_8T31IdA)相当于求 字符串a 和 字符串b 是否可以相互组成 ,而这道题目是求 字符串a能否组成字符串b,而不用管字符串b 能不能组成字符串a。 本题判断第一个字符串ransom能不能由第二个字符串magazines里面的字符构成,但是这里需要注意两点。 @@ -75,7 +75,7 @@ public: 依然是数组在哈希法中的应用。 -一些同学可能想,用数组干啥,都用map完事了,**其实在本题的情况下,使用map的空间消耗要比数组大一些的,因为map要维护红黑树或者哈希表,而且还要做哈希函数。 所以数组更加简单直接有效!** +一些同学可能想,用数组干啥,都用map完事了,**其实在本题的情况下,使用map的空间消耗要比数组大一些的,因为map要维护红黑树或者哈希表,而且还要做哈希函数,是费时的!数据量大的话就能体现出来差别了。 所以数组更加简单直接有效!** 代码如下: diff --git a/problems/面试题02.07.链表相交.md b/problems/面试题02.07.链表相交.md index 78f34e71..c6779427 100644 --- a/problems/面试题02.07.链表相交.md +++ b/problems/面试题02.07.链表相交.md @@ -32,11 +32,11 @@ 看如下两个链表,目前curA指向链表A的头结点,curB指向链表B的头结点: -![面试题02.07.链表相交_1](https://code-thinking.cdn.bcebos.com/pics/%E9%9D%A2%E8%AF%95%E9%A2%9802.07.%E9%93%BE%E8%A1%A8%E7%9B%B8%E4%BA%A4_1.png)v +![面试题02.07.链表相交_1](https://code-thinking.cdn.bcebos.com/pics/面试题02.07.链表相交_1.png) 我们求出两个链表的长度,并求出两个链表长度的差值,然后让curA移动到,和curB 末尾对齐的位置,如图: -![面试题02.07.链表相交_2](https://code-thinking.cdn.bcebos.com/pics/%E9%9D%A2%E8%AF%95%E9%A2%9802.07.%E9%93%BE%E8%A1%A8%E7%9B%B8%E4%BA%A4_2.png) +![面试题02.07.链表相交_2](https://code-thinking.cdn.bcebos.com/pics/面试题02.07.链表相交_2.png) 此时我们就可以比较curA和curB是否相同,如果不相同,同时向后移动curA和curB,如果遇到curA == curB,则找到焦点。