-
Notifications
You must be signed in to change notification settings - Fork 0
/
leecode_1.go
60 lines (54 loc) · 917 Bytes
/
leecode_1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import "fmt"
func twoSum(nums []int, target int) []int {
for i, v := range nums {
for ii, vv := range nums {
switch v+vv == target && i != ii {
case true:
return []int{i, ii}
}
}
}
return []int{}
}
func main() {
a := []int{2, 7, 11, 15}
t := 9
fmt.Println(twoSum(a, t))
}
/// go routine 寫法
//package main
//import (
// "fmt"
// "sync"
//)
//
//var wg sync.WaitGroup
//var na []int
//
//func second(a []int, b []int, target int) []int {
// for i, v := range b {
// if a[1]+v == target {
// na = []int{a[0], i + 1}
// }
// }
// wg.Done()
// return []int{}
//}
//func twoSum(nums []int, target int) []int {
// wg.Add(len(nums))
// for i, v := range nums {
// go second([]int{i, v}, nums[i+1:], target)
// }
// wg.Wait()
// if len(na) >1{return na}
// return []int{}
//}
//func main() {
// a := []int{2, 7, 11, 15}
// t := 9
//
// twoSum(a, t)
//
// fmt.Println(na)
//}