随笔分类 -  Go语言

摘要:package main import ( "fmt" "log" "sync" "time" ) type LRUCache struct { Caches map[string]NodeCache sync.Mutex } type NodeCache struct { Obj interfac 阅读全文
posted @ 2021-03-29 23:02 A毛毛 阅读(154) 评论(0) 推荐(0)
摘要:package main import "fmt" func main() { arr := []int{8, 10, 2, 4, 3, 5, 1, 6, 7} fmt.Println(arr) heapSort(arr, len(arr)) fmt.Println(arr) } // 堆排序 fu 阅读全文
posted @ 2020-12-13 23:12 A毛毛 阅读(172) 评论(0) 推荐(0)
摘要:package main import "fmt" func main() { arr := []int{10, 8, 2, 4, 3, 5, 1, 6, 7, 9} fmt.Println(arr) shellSort(arr) fmt.Println(arr) } func shellSort( 阅读全文
posted @ 2020-12-13 11:31 A毛毛 阅读(134) 评论(0) 推荐(0)
摘要:package main import "fmt" var arr = []int{7, 6, 8, 3, 5, 2, 4, 9, 1, 0} var tmpArr = make([]int, len(arr)) func main() { fmt.Println(arr) quickSort(ar 阅读全文
posted @ 2020-12-12 21:20 A毛毛 阅读(300) 评论(0) 推荐(0)
摘要:冒泡排序,小的数据不断从后面往前面冒泡 package main import "fmt" func main() { arr := []int{10, 2, 6, 8, 7, 5, 3, 4, 1, 9} fmt.Println(arr) bubbleSort(arr) fmt.Println(a 阅读全文
posted @ 2020-12-12 19:59 A毛毛 阅读(122) 评论(0) 推荐(0)
摘要:package main import "fmt" func main() { arr := []int{10, 2, 6, 8, 7, 5, 3, 4, 1, 9} insertSort(arr) fmt.Println(arr) } func insertSort(arr []int) { fo 阅读全文
posted @ 2020-12-12 18:51 A毛毛 阅读(111) 评论(0) 推荐(0)
摘要:package main import "fmt" func main() { arr := []int{10, 2, 6, 8, 7, 5, 3, 4, 1, 9} selectSort(arr) fmt.Println(arr) } func selectSort(arr []int) { ll 阅读全文
posted @ 2020-12-12 18:01 A毛毛 阅读(117) 评论(0) 推荐(0)
摘要:package main import ( "fmt" ) var arr = []int{10, 5, 3, 9, 2, 3, 7, 8, 1, 25, 12} var arrTmp = make([]int, len(arr)) func main() { fmt.Println(arr) Me 阅读全文
posted @ 2020-12-09 21:49 A毛毛 阅读(213) 评论(0) 推荐(0)
摘要:问题 给你 k 种面值的硬币,面值分别为 c1, c2 ... ck , 每种硬币的数量无限,再给一个总金额 amount , 问你最少需要几枚硬币凑出这个 金额,如果不可能凑出,算法返回 -1 思路 要凑出金额 11,至少要 dp(coins,11) 个硬币; 假如第一次凑1块,那么还有11-1块 阅读全文
posted @ 2020-12-06 21:36 A毛毛 阅读(444) 评论(0) 推荐(0)
摘要:问题 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数 实现思路: 1. 递归:踏上第n台阶之前,可能位于 第n-1个台阶 或 第n-2个台阶 2. 备忘map:缓存已经算过的记录,减少子问题个数,降 阅读全文
posted @ 2020-12-05 22:37 A毛毛 阅读(260) 评论(0) 推荐(0)
摘要:package main import ( "fmt" "time" ) func main() { // 斐波那契数列 start := time.Now().UnixNano() nRes := fibo(30) fmt.Println(nRes) end := time.Now().UnixN 阅读全文
posted @ 2020-12-05 20:04 A毛毛 阅读(338) 评论(0) 推荐(0)
摘要:package main import ( "encoding/json" "fmt" "math" "math/rand" "sort" "time" ) type Prize struct { PlayerId int64 Weight int } func main() { //设置奖项名称、 阅读全文
posted @ 2020-11-20 09:54 A毛毛 阅读(3180) 评论(0) 推荐(0)
摘要:package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "这是请求中的路径:", r.URL.Path) fmt.Fprintln( 阅读全文
posted @ 2020-02-13 13:08 A毛毛 阅读(1752) 评论(0) 推荐(0)
摘要:由于国内网络原因,因此访问https://golang.org/网站会被限制。所以在go get下载其他第三方包的时候,如果这个第三方包又引用了https://golang.org/x/下的包,通常会下载失败,就会报这个错误。 解决方法通常是拨VPN到海外进行下载,在这里我就把下载好的包放githu 阅读全文
posted @ 2020-02-12 00:07 A毛毛 阅读(3867) 评论(0) 推荐(0)
摘要:package main import ( "bytes" "encoding/hex" "fmt" "math/big" ) var base58Alphabets = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwx 阅读全文
posted @ 2020-01-29 23:49 A毛毛 阅读(1385) 评论(0) 推荐(0)
摘要:package main import ( "encoding/base64" "fmt" ) func main() { str := "Man" fmt.Println("原字符串是:", str) enStr := Base64EncodeString(str) fmt.Println("编码 阅读全文
posted @ 2020-01-29 22:27 A毛毛 阅读(2080) 评论(0) 推荐(0)
摘要:package main import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" "crypto/sha256" "encoding/hex" "fmt" "log" "math/big" ) func main() { // 1、对需要签名的 阅读全文
posted @ 2020-01-29 11:47 A毛毛 阅读(736) 评论(0) 推荐(0)
摘要:package main import ( "crypto" "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/base64" "encoding/pem" "errors" "fmt" "io/ioutil" ) func main() { st 阅读全文
posted @ 2020-01-28 22:37 A毛毛 阅读(2514) 评论(0) 推荐(0)
摘要:package main import ( "bytes" "crypto/aes" "crypto/cipher" "crypto/des" "encoding/base64" "fmt" ) // main 入口函数 func main() { // DES密钥 key := "12345678 阅读全文
posted @ 2020-01-28 10:07 A毛毛 阅读(984) 评论(0) 推荐(0)
摘要:验证结果网址 http://www.fileformat.info/tool/hash.htm "golang.org/x/crypto/md4"不存在时,解决方法: cd $GOPATH/src mkdir -p golang.org/x/ cd golang.org/x/ git clone h 阅读全文
posted @ 2020-01-27 08:16 A毛毛 阅读(1654) 评论(0) 推荐(0)