算法
泪光雨99
这个作者很懒,什么都没留下…
展开
-
两个goroutine ping-pong通信
package mainimport ( "fmt" "os" "os/signal" "sync" //"time")func main() { var wg = sync.WaitGroup{} wg.Add(1) quit1 := make(chan bool, 1) quit2 := make(chan bool, 1) quit3 := make(chan bool, 1) go func() { goroutine(quit1, quit2, quit3, &原创 2021-08-18 16:19:13 · 423 阅读 · 0 评论 -
添加运算符go语言
```gopackage mainimport ( "fmt" "regexp" "strconv")func main() { str := "202" var target int64 = 2 if !isNum(str) { return } addOperators(str, target)}func addOperators(str string, target int64) { res := []string{} backtrack(str, "", .原创 2021-08-17 14:32:09 · 98 阅读 · 0 评论 -
两个字符串的最长公共子串(go语言)
package mainimport ( "fmt")func main() { fmt.Println(getLCS("acbcbcef", "abcbced"))}func getLCS(str1, str2 string) string { record := make([][]int, len(str1)) for i := range record { record[i] = make([]int, len(str2)) } var maxLen = 0 var .原创 2021-08-13 17:10:50 · 464 阅读 · 0 评论 -
go 排序汇总
1、归并排序package mainimport ( "fmt" "math/rand")func main() { var z []int for i := 0; i < 10; i++ { z = append(z, rand.Intn(10)) } mergeSort(z, 0, 9)}func mergeSort(nums []int, start, end int) { if start >= end { return } mid := (s原创 2021-08-12 14:23:45 · 110 阅读 · 0 评论 -
输入一个字符串,一个n(代表n行),打印N字形
package mainimport ( "fmt")func main() { nFontPrint("HelloWorld", 5)}func nFontPrint(str string, n int) { col := len(str)/n + n - 1 arr := make([][]string, n) for i := range arr { arr[i] = make([]string, col) } direct := 1 cum := 0 j := 0原创 2021-08-12 16:35:26 · 1466 阅读 · 0 评论