09 2021 档案

摘要:203.移除链表元素 力扣链接 创建一个虚拟头节点 func removeElements(head *ListNode, val int) *ListNode { p:=&ListNode{} p.Next=head q:=p for p!=nil&&p.Next!=nil{ if p.Next. 阅读全文
posted @ 2021-09-28 20:29 CJ-cooper 阅读(240) 评论(0) 推荐(0)
摘要:704. 二分查找 力扣链接 注意边界问题 func search(nums []int, target int) int { r,l,mid:=0,len(nums)-1,(len(nums)-1)/2 for l>=r{ mid = (r+l)/2 if nums[mid]==target{ r 阅读全文
posted @ 2021-09-24 17:19 CJ-cooper 阅读(125) 评论(0) 推荐(0)
摘要:GMP Goroutine调度是一个很复杂的机制,下面尝试用简单的语言描述一下Goroutine调度机制,想要对其有更深入的了解可以去研读一下源码。 介绍 首先介绍一下GMP什么意思: G goroutine: 即Go协程,每个go关键字都会创建一个协程。 M thread内核级线程,所有的G都要放 阅读全文
posted @ 2021-09-15 01:39 CJ-cooper 阅读(6917) 评论(1) 推荐(0)
摘要:516.最长回文子序列 题目 思路 回文子序列都是动态规划经典题目,用从Carl哥那里学来的动态规划五部曲: 确定dp数组以及下标的含义 确定递推公式 dp数组如何初始化 确定遍历顺序 列举推导dp数组 确定dp数组以及下标的含义 dp[i] [j]:字符串s在[i, j]范围内最长的回文子序列的长 阅读全文
posted @ 2021-09-14 20:27 CJ-cooper 阅读(276) 评论(0) 推荐(0)
摘要:Golang抢占式调度 在1.2版本之前,go的调度器仍然不支持抢占式调度,程序只能依靠Goroutine主动让出CPU资源才能触发调度,这会引发一些问题,比如: 某些 Goroutine 可以长时间占用线程,造成其它 Goroutine 的饥饿 垃圾回收器是需要stop the world的。如果 阅读全文
posted @ 2021-09-13 22:21 CJ-cooper 阅读(686) 评论(0) 推荐(0)
摘要:今天刷力扣碰到要求最大公因数,总结一下。 方法 用到的方法是辗转相除法,具体思路如下: 代码实现 func gcd(a,b int)int{ if a%b==0{ return b } return gcd(b,a%b) } 或者 func gcd(a,b int)int{ for a%b!=0{ 阅读全文
posted @ 2021-09-12 21:29 CJ-cooper 阅读(252) 评论(0) 推荐(0)
摘要:解决 生成令牌 首先生成一个令牌,←链接是官网教程,也可以不点,直接看下文。 1、点击Settings 2、点击左侧的Developer settings 3、点击Personal access tokens(个人访问令牌) 4、点击Generate new token 5、设置token信息 点击 阅读全文
posted @ 2021-09-12 18:37 CJ-cooper 阅读(142) 评论(0) 推荐(0)
摘要:Channel 底层数据结构 type hchan struct { qcount uint // 当前队列中剩余元素个数 dataqsiz uint // 环形队列长度,即可以存放的元素个数 buf unsafe.Pointer // 环形队列指针 elemsize uint16 // 每个元素的 阅读全文
posted @ 2021-09-09 15:45 CJ-cooper 阅读(406) 评论(0) 推荐(0)
摘要:问题: 运行 ./goland.sh报错 OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future 阅读全文
posted @ 2021-09-06 18:49 CJ-cooper 阅读(618) 评论(0) 推荐(0)
摘要:1:二维数组按照第一列大小排序 import ( "fmt" "sort" ) func main() { interval := [][]int{ {2,3}, {2,2}, {3,3}, {1,3}, {5,7}, {2,2}, {4,6}, } sort.Slice(interval, fun 阅读全文
posted @ 2021-09-05 13:44 CJ-cooper 阅读(1381) 评论(0) 推荐(0)