We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 87256c4 commit 46b0ed5Copy full SHA for 46b0ed5
.vscode/settings.json
@@ -16,5 +16,8 @@
16
},
17
"python.testing.pytestArgs": ["solutions"],
18
"python.testing.unittestEnabled": false,
19
- "python.testing.pytestEnabled": true
+ "python.testing.pytestEnabled": true,
20
+ "github.copilot.enable": {
21
+ "python": "false"
22
+ }
23
}
solutions/solution_0128/__init__.py
@@ -1,2 +1,17 @@
1
class Solution:
2
- def longestConsecutive(self, nums: list[int]) -> int: ...
+ def longestConsecutive(self, nums: list[int]) -> int:
3
+ num_set = set(nums)
4
+ max_length = 0
5
+
6
+ for num in num_set:
7
+ if num - 1 not in num_set:
8
+ current_num = num
9
+ current_length = 1
10
11
+ while current_num + 1 in num_set:
12
+ current_num += 1
13
+ current_length += 1
14
15
+ max_length = max(max_length, current_length)
+ return max_length
0 commit comments