Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4674f26

Browse files
Merge pull request neetcode-gh#251 from zuruoke/main
added 1_twoSum solution golang
2 parents 1587b94 + 393b82b commit 4674f26

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package arrayandhashing
2+
3+
func twoSum(nums []int, target int) []int {
4+
m := make(map[int]int)
5+
for idx, num := range nums {
6+
7+
if val, found := m[target-num]; found {
8+
return []int{val, idx}
9+
}
10+
11+
m[num] = idx
12+
}
13+
return nil
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package arrayAndHashing
2+
3+
func containsDuplicate(nums []int) bool {
4+
freqMap := make(map[int]int)
5+
6+
for i := 0; i < len(nums); i++ {
7+
if _, ok := freqMap[nums[i]]; ok {
8+
return true
9+
}
10+
freqMap[nums[i]] += 1
11+
}
12+
return false
13+
}

0 commit comments

Comments
 (0)