Skip to content

Commit e987a66

Browse files
authored
Update 128._Longest_Consecutive_Sequence.md
1 parent 71f5386 commit e987a66

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

docs/Leetcode_Solutions/C++/128._Longest_Consecutive_Sequence.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# 128. Longest Consecutive Sequence
22

3-
**<font color=red>难度:Hard<font>**
3+
**<font color=red>难度:Hard<font>**
44

5-
## 刷题内容
6-
> 原题连接
5+
## 刷题内容
6+
> 原题连接
77
8-
* https://leetcode.com/problems/longest-consecutive-sequence/submissions/
8+
* https://leetcode.com/problems/longest-consecutive-sequence/
99

10-
> 内容描述
10+
> 内容描述
1111
1212
```
1313
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
@@ -21,10 +21,10 @@ Output: 4
2121
Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
2222
```
2323

24-
> 思路1
25-
******- 时间复杂度: O(n)******- 空间复杂度: O(1)******
24+
> 思路1
25+
******- 时间复杂度: O(n)******- 空间复杂度: O(1)******
2626

27-
先对数组进行排序。在用unique()函数去除重复的数字。在遍历数组,找到最长的连续数字。时间复杂度为O(nlgn)。
27+
先对数组进行排序。在用unique()函数去除重复的数字。在遍历数组,找到最长的连续数字。时间复杂度为O(nlgn)。
2828

2929
```cpp
3030
class Solution {
@@ -48,9 +48,9 @@ public:
4848
}
4949
};
5050
```
51-
> 思路2
52-
******- 时间复杂度: O(nlgn)******- 空间复杂度: O(1)******
53-
c++中的unordered_map是用hash桶实现的,所以可以在线性时间内完成。县遍历数组,用nums[i]作为unordered_map的键值。0作为 value。0表示此时的nums[i]还没被遍历过。接着遍历数组,用DFS搜索每个nums[i]的最长连续数字。被遍历过的nums[i]的unordered_map值设为1
51+
> 思路2
52+
******- 时间复杂度: O(nlgn)******- 空间复杂度: O(1)******
53+
c++中的unordered_map是用hash桶实现的,所以可以在线性时间内完成。县遍历数组,用nums[i]作为unordered_map的键值。0作为 value。0表示此时的nums[i]还没被遍历过。接着遍历数组,用DFS搜索每个nums[i]的最长连续数字。被遍历过的nums[i]的unordered_map值设为1
5454
```cpp
5555
class Solution {
5656
public:
@@ -80,4 +80,4 @@ public:
8080
return ans;
8181
}
8282
};
83-
```
83+
```

0 commit comments

Comments
 (0)