File tree 2 files changed +24
-1
lines changed
src/0128-Longest-Consecutive-Sequence
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ LeetCode
131
131
| 0125| [ Valid Palindrome] ( https://leetcode.com/problems/valid-palindrome/ ) || [ c++] ( ./src/0125-Valid-Palindrome/0125.cpp ) | [ python] ( ./src/0125-Valid-Palindrome/0125.py ) ||||| Easy|
132
132
| 0126| [ Word Ladder II] ( https://leetcode.com/problems/word-ladder-ii/ ) || [ c++] ( ./src/0126-Word-Ladder-II/0126.cpp ) | [ python] ( ./src/0126-Word-Ladder-II/0126.py ) ||||| Hard|
133
133
| 0127| [ Word Ladder] ( https://leetcode.com/problems/word-ladder/ ) || [ c++] ( ./src/0127-Word-Ladder/0127.cpp ) | [ python] ( ./src/0127-Word-Ladder/0127.py ) ||||| Medium|
134
- | 0128| [ Longest Consecutive Sequence] ( https://leetcode.com/problems/longest-consecutive-sequence/ ) || [ c++] ( ./src/0128-Longest-Consecutive-Sequence/0128.cpp ) | [ python] ( ./src/0128-Longest-Consecutive-Sequence/0128.py ) ||||| Hard|
134
+ | 0128| [ Longest Consecutive Sequence] ( https://leetcode.com/problems/longest-consecutive-sequence/ ) || [ c++] ( ./src/0128-Longest-Consecutive-Sequence/0128.cpp ) | [ python] ( ./src/0128-Longest-Consecutive-Sequence/0128.py ) | [ go ] ( ./src/0128-Longest-Consecutive-Sequence/0128.go ) |||| Hard|
135
135
| 0129| [ Sum Root to Leaf Numbers] ( https://leetcode.com/problems/sum-root-to-leaf-numbers/ ) || [ c++] ( ./src/0129-Sum-Root-to-Leaf-Numbers/0129.cpp ) | [ python] ( ./src/0129-Sum-Root-to-Leaf-Numbers/0129.py ) ||||| Medium|
136
136
| 0130| [ Surrounded Regions] ( https://leetcode.com/problems/surrounded-regions/ ) || [ c++] ( ./src/0130-Surrounded-Regions/0130.cpp ) | [ python] ( ./src/0130-Surrounded-Regions/0130.py ) ||||| Medium|
137
137
| 0131| [ Palindrome Partitioning] ( https://leetcode.com/problems/palindrome-partitioning/ ) || [ c++] ( ./src/0131-Palindrome-Partitioning/0131.cpp ) | [ python] ( ./src/0131-Palindrome-Partitioning/0131.py ) ||||| Medium|
Original file line number Diff line number Diff line change
1
+ package longestconsecutivesequence
2
+
3
+ func longestConsecutive (nums []int ) int {
4
+ mp := make (map [int ]bool )
5
+ for _ , val := range nums {
6
+ mp [val ] = true
7
+ }
8
+ ans := 0
9
+ for _ , val := range nums {
10
+ _ , ex := mp [val - 1 ]
11
+ if ! ex {
12
+ curr_val , count := val , 0
13
+ for mp [curr_val ] {
14
+ curr_val += 1
15
+ count += 1
16
+ }
17
+ if count > ans {
18
+ ans = count
19
+ }
20
+ }
21
+ }
22
+ return ans
23
+ }
You can’t perform that action at this time.
0 commit comments