摘要: 所列题目与牛客网《剑指offer》专题相对应。 数组: 和为S的两个数字 和为S的连续正数序列 连续子数组的最大和 数字在排序数组中出现的次数 数组中只出现一次的数字 旋转数组的最小数字 数组中的逆序对 最小的K个数 数组中出现次数超过一半的数字 把数组排成最小的数 数组中重复的数字 滑动窗口的最大 阅读全文
posted @ 2019-12-08 22:21 南方有嘉木1993 阅读(1784) 评论(0) 推荐(0) 编辑
摘要: select语句用来处理与channel有关的I/O操作。 语法: 每个case都必须是一个通信;所有channel表达式和被发送的... 阅读全文
posted @ 2020-11-22 17:37 南方有嘉木1993 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 服务端实现 package main import ( "encoding/json" "fmt" "log" "net/http" "golang.org/x/net/websocket" ) func add(ws *websocket.Conn) { msg := make([]byte, 5 阅读全文
posted @ 2020-11-15 16:51 南方有嘉木1993 阅读(1737) 评论(0) 推荐(0) 编辑
摘要: 安装 安装protobuf go get -u github.com/golang/protobuf/proto go get -u... 阅读全文
posted @ 2020-10-15 16:31 南方有嘉木1993 阅读(304) 评论(0) 推荐(0) 编辑
摘要: net/rpc库 server: package mainimport ( "fmt" "log" "net/http" "net/... 阅读全文
posted @ 2020-10-15 16:29 南方有嘉木1993 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Sprintf 四舍六入: value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", 9.824), 64) fmt.Println(value) //9.82 value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f 阅读全文
posted @ 2020-06-27 15:44 南方有嘉木1993 阅读(11030) 评论(0) 推荐(1) 编辑
摘要: 1.服务启动: Windows: 1.在window的环境变量中path加入: E:\nsq-1.0.0-compat.windows-amd64.go1.8\bin 2.打开命令窗口,运行: nsqlookupd 3.打开新的命令窗口,运行: nsqd --broadcast-address=12 阅读全文
posted @ 2020-03-13 08:17 南方有嘉木1993 阅读(413) 评论(0) 推荐(0) 编辑
摘要: ** 1.Type(expression): ** int(time.Now().Weekday()) //星期转int int(time.Now().Month()) //月份转int var a float64 a = 3.1 b := int(a) //float64转int var a in 阅读全文
posted @ 2020-03-03 09:41 南方有嘉木1993 阅读(887) 评论(0) 推荐(0) 编辑
摘要: 下载cron包: go get github.com/robfig/cron 开启一个定时: 根据cron表达式进行时间调度,cron可以精确到秒,大部分表达式格式也是从秒开始。 c := cron.New()默认从分开始,所以加上cron.WithSeconds(),保证定时按照表达式字面意思执行 阅读全文
posted @ 2020-02-18 19:50 南方有嘉木1993 阅读(2685) 评论(0) 推荐(0) 编辑
摘要: Gorm连接MySQL: import ( _ "github.com/go-sql-driver/mysql" "github.com/jinzhu/gorm" ) type User struct { Id int `json:"id"` Name string `json:"name"` Ag 阅读全文
posted @ 2019-12-25 11:18 南方有嘉木1993 阅读(1578) 评论(0) 推荐(0) 编辑
摘要: 冒泡排序: 时间复杂度:O(n^2) 稳定性:稳定 //冒泡排序 //相邻两位交换,12交换,23交换,34交换,把最大的数放到最右边 //利用flag标记可以避免无效循环 func BubbleSort(arr []int) { length := len(arr) //length是最后一位,i 阅读全文
posted @ 2019-12-19 16:32 南方有嘉木1993 阅读(263) 评论(0) 推荐(0) 编辑