LeetCode - Two Sum 完整代码(GO)

LeetCode - Two Sum 完整代码(GO)

要求:

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

源码:

package main

import(
        "fmt"
)

func two_sum(nums []int, target int) []int{
        aa := []int{}
        m := make(map[int]int)
        for i:=0;i


测试方法:

先输入三个待匹配的数字,以空格隔开,再输入一个目标数字,最后得出是否有两个相加的数字匹配。

举例如下:

$ go run two_sum2.go 
please input three digit:
12 43 8
please input the target:
51
the data match the target
[1 2]



你可能感兴趣的:(golang)