Skip to content

Latest commit

 

History

History
13 lines (13 loc) · 312 Bytes

1两数之和.md

File metadata and controls

13 lines (13 loc) · 312 Bytes
func twoSum(nums []int, target int) []int {
    // 用map来记录出现的数字,数值为key,下标为value
    table := map[int]int{}
    for i, n := range nums {
        if k, ok := table[target - n]; ok {
            return []int{k, i}
        }
        table[n] = i
    }
    return []int{}
}