We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4cc1ee7 commit 44ba114Copy full SHA for 44ba114
167.Two-Sum-II-Input-array-is-sorted.go
@@ -0,0 +1,27 @@
1
+// https://leetcode.com/problems/compare-version-numbers/
2
+//
3
+// algorithms
4
+// Easy (48.56%)
5
+// Total Accepted: 196,893
6
+// Total Submissions: 405,472
7
+// beats 100.0% of golang submissions
8
+
9
+package leetcode
10
11
+func twoSum(numbers []int, target int) []int {
12
+ hashMap := make(map[int]int)
13
14
+ for idx, n := range numbers {
15
+ if v, ok := hashMap[target-n]; ok {
16
+ if idx > v {
17
+ return []int{v + 1, idx + 1}
18
+ } else {
19
+ return []int{idx + 1, v + 1}
20
+ }
21
22
+ hashMap[n] = idx
23
24
25
26
+ return []int{}
27
+}
0 commit comments