[LeetCode]1.Two Sum
題解:
簡單雜湊表
程式碼
func twoSum(nums []int, target int) []int {
var result []int
m := make(map[int]int)
for i, v := range nums {
if prev_idx, ok := m[target-v]; ok {
result = append(result, prev_idx, i)
break
} else {
m[v] = i
}
}
return result
}
相關文章
- LeetCode 1.Two NumsLeetCode
- Leetcode Path SumLeetCode
- leetcode Sum系列LeetCode
- Leetcode Two SumLeetCode
- leetcode15&16_3Sum&4SumLeetCode
- Leetcode 1 two sumLeetCode
- Leetcode 3SumLeetCode
- Leetcode 4SumLeetCode
- Leetcode Path Sum IILeetCode
- Leetcode-Path SumLeetCode
- Leetcode-Two SumLeetCode
- Leetcode-3SumLeetCode
- Path Sum leetcode javaLeetCodeJava
- Two Sum leetcode javaLeetCodeJava
- 3 Sum leetcode javaLeetCodeJava
- 4 Sum leetcode javaLeetCodeJava
- LeetCode | 1 Two SumLeetCode
- Leetcode 15 3SumLeetCode
- Leetcode 18 4SumLeetCode
- LeetCode----1. Two SumLeetCode
- Leetcode - Partition Equal Subset SumLeetCode
- LeetCode-3Sum SmallerLeetCode
- LeetCode-Count of Range SumLeetCode
- LeetCode1:Two SumLeetCode
- Leetcode 3Sum ClosestLeetCode
- Leetcode Sum Root to Leaf NumbersLeetCode
- Leetcode Minimum Path SumLeetCode
- Leetcode-Path Sum IILeetCode
- Leetcode-3Sum ClosestLeetCode
- Path Sum II leetcode javaLeetCodeJava
- [LeetCode]1. Two SumLeetCode
- LeetCode OJ : 1 Two SumLeetCode
- LeetCode-1 Two SumLeetCode
- LeetCode 259. Three Sum SmallerLeetCode
- LeetCode: Two sum(兩數之和)LeetCode
- Leetcode 16 3Sum ClosestLeetCode
- python: leetcode - 1 Two SumPythonLeetCode
- LeetCode Problem-Sum of Two IntegersLeetCode