暂无

暂无

暂无

## 最近的评论

• 什么原理？
• #6 @freboat 粘丢了 如下 ``` func addNA(arr, arr2 []uint64) []uint64 { reArr := make([]uint64, 0) for i:=0; i<len(arr); i++ { for j:=0; j<len(arr2); j++ { n := arr[i] * arr2[j] for k:=len(reArr)-1; k>=0; k-- { if n == reArr[k] { goto NEXT } } if n !=0 { reArr = append(reArr, n) } NEXT: } } return reArr } ```
• ```go package main import ( "fmt" "time" "sort" ) func main() { fmt.Println("begin") arr := []uint64{2,3,5} length := 10000 beginTime := time.Now() arr = t2(length, arr) endTime := time.Now() fmt.Println(arr) fmt.Println(arr[length-1]) fmt.Println("end") fmt.Println("用时", endTime.Unix() - beginTime.Unix(), "s") } func t2(lenth int, arr []uint64) []uint64 { reArr := arr backArr := arr for ; len(backArr) < lenth; { backArr = addNA(arr, backArr) reArr = append(reArr, backArr...) } rr := Int64Slice(reArr) sort.Sort(rr) return rr[0:lenth] } func addNA(arr, arr2 []uint64) []uint64 { reArr := make([]uint64, 0) for i:=0; i<len(arr); i++ { for j:=0; j<len(arr2); j++ { n := arr[i] * arr2[j] for k:=len(reArr)-1; k>=0; k-- { if n == reArr[k] { goto NEXT } } if n !=0 { reArr = append(reArr, n) } NEXT: } } return reArr } type Int64Slice []uint64 func (p Int64Slice) Len() int { return len(p) } func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] } func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } ``` ![image.png](https://static.studygolang.com/180310/1f3b06031e7635f0bde8a405a3de5f62.png)