Skip to content

Commit 44ba114

Browse files
committed
feat(leetcode): add No.167
1 parent 4cc1ee7 commit 44ba114

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
} else {
22+
hashMap[n] = idx
23+
}
24+
}
25+
26+
return []int{}
27+
}

0 commit comments

Comments
 (0)