File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 9
9
10
10
## 1. 两数之和
11
11
12
- https://leetcode-cn.com/problems/two-sum/
12
+ [ 力扣题目链接 ] ( https://leetcode-cn.com/problems/two-sum/ )
13
13
14
14
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
15
15
@@ -29,10 +29,10 @@ https://leetcode-cn.com/problems/two-sum/
29
29
很明显暴力的解法是两层for循环查找,时间复杂度是O(n^2)。
30
30
31
31
建议大家做这道题目之前,先做一下这两道
32
- * [ 242. 有效的字母异位词] ( https://mp.weixin.qq. com/s/ffS8jaVFNUWyfn_8T31IdA )
33
- * [ 349. 两个数组的交集] ( https://mp.weixin.qq. com/s/aMSA5zrp3jJcLjuSB0Es2Q )
32
+ * [ 242. 有效的字母异位词] ( https://www.programmercarl. com/0242.有效的字母异位词.html )
33
+ * [ 349. 两个数组的交集] ( https://www.programmercarl. com/0349.两个数组的交集.html )
34
34
35
- [ 242. 有效的字母异位词] ( https://mp.weixin.qq. com/s/ffS8jaVFNUWyfn_8T31IdA ) 这道题目是用数组作为哈希表来解决哈希问题,[ 349. 两个数组的交集] ( https://mp.weixin.qq. com/s/aMSA5zrp3jJcLjuSB0Es2Q ) 这道题目是通过set作为哈希表来解决哈希问题。
35
+ [ 242. 有效的字母异位词] ( https://www.programmercarl. com/0242.有效的字母异位词.html ) 这道题目是用数组作为哈希表来解决哈希问题,[ 349. 两个数组的交集] ( https://www.programmercarl. com/0349.两个数组的交集.html ) 这道题目是通过set作为哈希表来解决哈希问题。
36
36
37
37
本题呢,则要使用map,那么来看一下使用数组和set来做哈希法的局限。
38
38
@@ -51,7 +51,7 @@ C++中map,有三种类型:
51
51
52
52
std::unordered_map 底层实现为哈希表,std::map 和std::multimap 的底层实现是红黑树。
53
53
54
- 同理,std::map 和std::multimap 的key也是有序的(这个问题也经常作为面试题,考察对语言容器底层的理解)。 更多哈希表的理论知识请看[ 关于哈希表,你该了解这些!] ( https://mp.weixin.qq. com/s/RSUANESA_tkhKhYe3ZR8Jg ) 。
54
+ 同理,std::map 和std::multimap 的key也是有序的(这个问题也经常作为面试题,考察对语言容器底层的理解)。 更多哈希表的理论知识请看[ 关于哈希表,你该了解这些!] ( https://www.programmercarl. com/哈希表理论基础.html ) 。
55
55
56
56
** 这道题目中并不需要key有序,选择std::unordered_map 效率更高!**
57
57
You can’t perform that action at this time.
0 commit comments