Skip to content

Commit eba04d8

Browse files
authored
add: longest-consecutive-sequence solutio in go (#33)
1 parent 4ed0e6e commit eba04d8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ LeetCode
131131
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) || [c++](./src/0125-Valid-Palindrome/0125.cpp) |[python](./src/0125-Valid-Palindrome/0125.py)|||||Easy|
132132
|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|
133133
|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|
135135
|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|
136136
|0130|[Surrounded Regions](https://leetcode.com/problems/surrounded-regions/) || [c++](./src/0130-Surrounded-Regions/0130.cpp) |[python](./src/0130-Surrounded-Regions/0130.py)|||||Medium|
137137
|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 numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)