上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 21 下一页
摘要: 1、竞态问题 多个 goroutine 同时操作一个资源(临界区)的情况,这种情况下就会发生竞态问题。 2、互斥锁 互斥锁是一种常用的控制共享资源访问的方法,它能够保证同一时间只有一个 goroutine 可以访问共享资源。Go 语言中使用sync包中提供的Mutex类型来实现互斥锁。 sync.M 阅读全文
posted @ 2022-03-22 15:25 ☞@_@ 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 1、select的使用方法 Select 的使用方式类似于之前学到的 switch 语句,它也有一系列 case 分支和一个默认的分支。每个 case 分支会对应一个通道的通信(接收或发送)过程。select 会一直等待,直到其中的某个 case 的通信操作完成时,就会执行该 case 分支对应的语 阅读全文
posted @ 2022-03-22 15:09 ☞@_@ 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 1、通道的发送、接收以及关闭 ch := make(chan int) //发送 ch <- 10 // 把10发送到ch中 //接收 x := <- ch // 从ch中接收值并赋值给变量x <-ch // 从ch中接收值,忽略结果 //关闭 close(ch) 2、无缓冲通道和有缓冲通道 无缓冲 阅读全文
posted @ 2022-03-22 15:02 ☞@_@ 阅读(32) 评论(0) 推荐(0) 编辑
摘要: type MyStack struct { queue []int } /** Initialize your data structure here. */ func Constructor() (s MyStack) { return } /** Push element x onto stac 阅读全文
posted @ 2022-03-20 15:13 ☞@_@ 阅读(8) 评论(0) 推荐(0) 编辑
摘要: type MyQueue struct { inStack, outStack []int } func Constructor() MyQueue { return MyQueue{} } func (q *MyQueue) Push(x int) { q.inStack = append(q.i 阅读全文
posted @ 2022-03-20 14:14 ☞@_@ 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 反转整个链表 /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func reverseList(head *ListNode) *ListNode 阅读全文
posted @ 2022-03-20 11:18 ☞@_@ 阅读(26) 评论(0) 推荐(0) 编辑
摘要: func getIntersectionNode(headA, headB *ListNode) *ListNode { if headA==nil||headB==nil{ return nil } p1,p2:=headA,headB for p1!=p2{ if p1==nil{ p1=hea 阅读全文
posted @ 2022-03-18 21:33 ☞@_@ 阅读(11) 评论(0) 推荐(0) 编辑
摘要: func detectCycle(head *ListNode) *ListNode { if head==nil||head.Next==nil{ return nil } p1,p2:=head,head for p2!=nil{ p1=p1.Next p2=p2.Next if p2!=nil 阅读全文
posted @ 2022-03-18 21:16 ☞@_@ 阅读(29) 评论(0) 推荐(0) 编辑
摘要: func hasCycle(head *ListNode) bool { if head==nil||head.Next==nil{ return false } p1,p2:=head,head.Next for p2!=nil{ p1=p1.Next p2=p2.Next if p2!=nil{ 阅读全文
posted @ 2022-03-18 21:00 ☞@_@ 阅读(4) 评论(0) 推荐(0) 编辑
摘要: // 返回链表的倒数第 k 个节点 ListNode findFromEnd(ListNode head, int k) { ListNode p1 = head; // p1 先⾛ k 步 for (int i = 0; i < k; i++) { p1 = p1.next; } ListNode 阅读全文
posted @ 2022-03-18 20:45 ☞@_@ 阅读(24) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 21 下一页