8000 3 · hitzzc/go-leetcode@983afbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 983afbf

Browse files
committed
3
1 parent 310e943 commit 983afbf

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
174174
#### [214. Shortest Palindrome (unsolved)](https://github.com/hitzzc/go-leetcode/tree/master/shortest_palindrome)
175175
#### [215. Kth Largest Element in an Array](https://github.com/hitzzc/go-leetcode/tree/master/kth_largest_element_in_an_array)
176176
#### [216. Combination Sum III](https://github.com/hitzzc/go-leetcode/tree/master/combinations_sum_III)
177+
#### [217. Contains Duplicate](https://github.com/hitzzc/go-leetcode/tree/master/contains_duplicate)
178+
#### [218. Contains Duplicate II](https://github.com/hitzzc/go-leetcode/tree/master/contains_duplicate_II)
179+
#### [219. Contains Duplicate III (unsolved)](https://github.com/hitzzc/go-leetcode/tree/master/contains_duplicate_III)
177180

178181

179182

+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package contains_duplicate
2+
3+
func containsDuplicate(nums []int) bool {
4+
m := map[int]bool{}
5+
for i := range nums {
6+
if m[nums[i]] {
7+
return true
8+
}
9+
m[nums[i]] = true
10+
}
11+
return false
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package contains_duplicate_II
2+
3+
func containsNearbyDuplicate(nums []int, k int) bool {
4+
m := map[int]int{}
5+
for i := range nums {
6+
if j, ok := m[nums[i]]; ok {
7+
if i-j <= k {
8+
return true
9+
}
10+
}
11+
m[nums[i]] = i
12+
}
13+
return false
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package contains_duplicate_III
2+
3+
func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool {
4+
5+
}

0 commit comments

Comments
 (0)
0