Skip to content

Commit c56fb5d

Browse files
committed
Update 1.two-sum.md
1 parent b6818a0 commit c56fb5d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

problems/1.two-sum.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ https://leetcode-cn.com/problems/two-sum
5353

5454
## 代码
5555

56-
- 语言支持:JS
56+
- 语言支持:JS, Go
5757

5858
```js
5959
/**
@@ -73,6 +73,23 @@ const twoSum = function (nums, target) {
7373
};
7474
```
7575

76+
Go Code:
77+
78+
```go
79+
func twoSum(nums []int, target int) []int {
80+
m := make(map[int]int)
81+
for i, _ := range nums {
82+
diff := target - nums[i]
83+
if j, ok := m[diff]; ok {
84+
return []int{i, j}
85+
} else {
86+
m[nums[i]] = i
87+
}
88+
}
89+
return []int{}
90+
}
91+
```
92+
7693
**复杂度分析**
7794

7895
- 时间复杂度:$O(N)$

0 commit comments

Comments
 (0)