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 fa9ea36 commit bb8d394Copy full SHA for bb8d394
longest-consecutive-sequence/youngDaLee.go
@@ -0,0 +1,28 @@
1
+package youngDaLee
2
+
3
+func longestConsecutive(nums []int) int {
4
+ numSet := make(map[int]bool)
5
+ for _, num := range nums {
6
+ numSet[num] = true
7
+ }
8
9
+ longestStreak := 0
10
11
+ for num := range numSet {
12
+ if !numSet[num-1] {
13
+ currentNum := num
14
+ currentStreak := 1
15
16
+ for numSet[currentNum+1] {
17
+ currentNum++
18
+ currentStreak++
19
20
21
+ if currentStreak > longestStreak {
22
+ longestStreak = currentStreak
23
24
25
26
27
+ return longestStreak
28
+}
0 commit comments