We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6818a0 commit c56fb5dCopy full SHA for c56fb5d
problems/1.two-sum.md
@@ -53,7 +53,7 @@ https://leetcode-cn.com/problems/two-sum
53
54
## 代码
55
56
-- 语言支持:JS
+- 语言支持:JS, Go
57
58
```js
59
/**
@@ -73,6 +73,23 @@ const twoSum = function (nums, target) {
73
};
74
```
75
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
93
**复杂度分析**
94
95
- 时间复杂度:$O(N)$
0 commit comments