Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76fd68c

Browse files
Merge pull request youngyangyang04#1963 from juguagua/leetcode-add-complexity-analysis-hashtable
添加复杂度分析:哈希表部分
2 parents c382ca0 + b03c9a9 commit 76fd68c

8 files changed

+35
-4
lines changed

‎problems/0001.两数之和.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public:
109109
};
110110
```
111111
112+
* 时间复杂度: O(n)
113+
* 空间复杂度: O(n)
114+
112115
## 总结
113116
114117
本题其实有四个重点:

‎problems/0015.三数之和.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public:
8383
};
8484
```
8585
86+
* 时间复杂度: O(n^2)
87+
* 空间复杂度: O(n),额外的 set 开销
88+
89+
8690
## 双指针
8791
8892
**其实这道题目使用哈希法并不十分合适**,因为在去重的操作中有很多细节需要注意,在面试中很难直接写出没有bug的代码。
@@ -158,6 +162,10 @@ public:
158162
};
159163
```
160164

165+
* 时间复杂度: O(n^2)
166+
* 空间复杂度: O(1)
167+
168+
161169
## 去重逻辑的思考
162170

163171
### a的去重

‎problems/0018.四数之和.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public:
121121

122122
```
123123

124+
* 时间复杂度: O(n^3)
125+
* 空间复杂度: O(1)
126+
127+
124128
## 补充
125129

126130
二级剪枝的部分:

‎problems/0202.快乐数.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public:
7575
};
7676
```
7777
78+
* 时间复杂度: O(logn)
79+
* 空间复杂度: O(logn)
7880
7981
8082

‎problems/0242.有效的字母异位词.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public:
8585
};
8686
```
8787
88+
* 时间复杂度: O(n)
89+
* 空间复杂度: O(1)
90+
8891
8992
9093
## 其他语言版本

‎problems/0349.两个数组的交集.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public:
7272
};
7373
```
7474
75+
* 时间复杂度: O(mn)
76+
* 空间复杂度: O(n)
77+
7578
## 拓展
7679
7780
那有同学可能问了,遇到哈希问题我直接都用set不就得了,用什么数组啊。
@@ -110,6 +113,8 @@ public:
110113
};
111114
```
112115

116+
* 时间复杂度: O(m + n)
117+
* 空间复杂度: O(n)
113118

114119
## 其他语言版本
115120

‎problems/0383.赎金信.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ canConstruct("aa", "aab") -> true
3939
那么第一个思路其实就是暴力枚举了,两层for循环,不断去寻找,代码如下:
4040

4141
```CPP
42-
// 时间复杂度: O(n^2)
43-
// 空间复杂度:O(1)
4442
class Solution {
4543
public:
4644
bool canConstruct(string ransomNote, string magazine) {
@@ -62,6 +60,9 @@ public:
6260
};
6361
```
6462
63+
* 时间复杂度: O(n^2)
64+
* 空间复杂度: O(1)
65+
6566
这里时间复杂度是比较高的,而且里面还有一个字符串删除也就是erase的操作,也是费时的,当然这段代码也可以过这道题。
6667
6768
@@ -78,8 +79,6 @@ public:
7879
代码如下:
7980
8081
```CPP
81-
// 时间复杂度: O(n)
82-
// 空间复杂度:O(1)
8382
class Solution {
8483
public:
8584
bool canConstruct(string ransomNote, string magazine) {
@@ -105,6 +104,10 @@ public:
105104
};
106105
```
107106

107+
* 时间复杂度: O(n)
108+
* 空间复杂度: O(1)
109+
110+
108111

109112

110113
## 其他语言版本

‎problems/0454.四数相加II.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public:
8383

8484
```
8585
86+
* 时间复杂度: O(n^2)
87+
* 空间复杂度: O(n^2),最坏情况下A和B的值各不相同,相加产生的数字个数为 n^2
88+
8689
8790
8891

0 commit comments

Comments
(0)

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