We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 07eb507 commit 234883eCopy full SHA for 234883e
data_structure/union_find.md
@@ -142,6 +142,24 @@ class Solution:
142
return max_length
143
```
144
145
+```Python
146
+class Solution:
147
+ def longestConsecutive(self, nums: List[int]) -> int:
148
+ nums_set = set(nums)
149
+ max_len = 0
150
+ # start from the lowest
151
+ for num in nums_set:
152
+ if num -1 not in nums_set:
153
+ length = 1
154
+ cur_num = num
155
+ while cur_num + 1 in nums_set:
156
+ length += 1
157
+ cur_num += 1
158
+ max_len = max(max_len, length)
159
+ return max_len
160
+
161
+```
162
163
### Kruskal's algorithm
164
165
### [minimum-risk-path](https://www.lintcode.com/problem/minimum-risk-path/description)
0 commit comments