File tree Expand file tree Collapse file tree 2 files changed +3
-3
lines changed Expand file tree Collapse file tree 2 files changed +3
-3
lines changed Original file line number Diff line number Diff line change 26
26
27
27
## 算法公开课
28
28
29
- ** [ 《代码随想录》算法视频公开课] ( https://programmercarl.com/other/gongkaike.html ) :[ 把环形链表讲清楚!| LeetCode:142.环形链表II] ( https://www.bilibili.com/video/BV1if4y1d7ob ) ,相信结合视频在看本篇题解 ,更有助于大家对链表的理解。**
29
+ ** [ 《代码随想录》算法视频公开课] ( https://programmercarl.com/other/gongkaike.html ) :[ 把环形链表讲清楚!| LeetCode:142.环形链表II] ( https://www.bilibili.com/video/BV1if4y1d7ob ) ,相信结合视频再看本篇题解 ,更有助于大家对链表的理解。**
30
30
31
31
## 思路
32
32
Original file line number Diff line number Diff line change 54
54
1 . 首先定义 一个unordered_map,key放a和b两数之和,value 放a和b两数之和出现的次数。
55
55
2 . 遍历大A和大B数组,统计两个数组元素之和,和出现的次数,放到map中。
56
56
3 . 定义int变量count,用来统计 a+b+c+d = 0 出现的次数。
57
- 4 . 在遍历大C和大D数组 ,找到如果 0-(c+d) 在map中出现过的话,就用count把map中key对应的value也就是出现次数统计出来。
57
+ 4 . 再遍历大C和大D数组 ,找到如果 0-(c+d) 在map中出现过的话,就用count把map中key对应的value也就是出现次数统计出来。
58
58
5 . 最后返回统计值 count 就可以了
59
59
60
60
C++代码:
@@ -71,7 +71,7 @@ public:
71
71
}
72
72
}
73
73
int count = 0; // 统计a+b+c+d = 0 出现的次数
74
- // 在遍历大C和大D数组 ,找到如果 0-(c+d) 在map中出现过的话,就把map中key对应的value也就是出现次数统计出来。
74
+ // 再遍历大C和大D数组 ,找到如果 0-(c+d) 在map中出现过的话,就把map中key对应的value也就是出现次数统计出来。
75
75
for (int c : C) {
76
76
for (int d : D) {
77
77
if (umap.find(0 - (c + d)) != umap.end()) {
You can’t perform that action at this time.
0 commit comments