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

Commitb53d170

Browse files
authored
Two Sum
1 parent0fc222c commitb53d170

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎Source Code/1. Two Sum/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#Solution
2+
3+
##Python
24
```
35
class Solution:
46
def twoSum(self, nums, target):
@@ -10,3 +12,19 @@ class Solution:
1012
else:
1113
new_dic[nums[x]] = x
1214
```
15+
16+
##Golang
17+
```
18+
func twoSum(nums []int, target int) []int {
19+
di := map[int]int{}
20+
21+
for i := 0; i <= len(nums); i++ {
22+
if idx, ok := di[target-nums[i]]; ok {
23+
return []int{idx, i}
24+
} else {
25+
di[nums[i]] = i
26+
}
27+
}
28+
return []int{}
29+
}
30+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp