添加(0141.环形链表.md):增加go版本

This commit is contained in:
xuerbujia
2022-03-26 10:03:04 +08:00
committed by GitHub
parent 79b2453233
commit 9dbc51455d

View File

@ -106,6 +106,21 @@ class Solution:
## Go
```go
func hasCycle(head *ListNode) bool {
if head==nil{
return false
} //空链表一定不会有环
fast:=head
slow:=head //快慢指针
for fast.Next!=nil&&fast.Next.Next!=nil{
fast=fast.Next.Next
slow=slow.Next
if fast==slow{
return true //快慢指针相遇则有环
}
}
return false
}
```
### JavaScript