Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4674f26

Browse files
Merge pull requestneetcode-gh#251 from zuruoke/main
added 1_twoSum solution golang
2 parents1587b94 +393b82b commit4674f26

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+
functwoSum(nums []int,targetint) []int {
4+
m:=make(map[int]int)
5+
foridx,num:=rangenums {
6+
7+
ifval,found:=m[target-num];found {
8+
return []int{val,idx}
9+
}
10+
11+
m[num]=idx
12+
}
13+
returnnil
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package arrayAndHashing
2+
3+
funccontainsDuplicate(nums []int)bool {
4+
freqMap:=make(map[int]int)
5+
6+
fori:=0;i<len(nums);i++ {
7+
if_,ok:=freqMap[nums[i]];ok {
8+
returntrue
9+
}
10+
freqMap[nums[i]]+=1
11+
}
12+
returnfalse
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp