LeetCode 141. 环形链表
题目描述
思路分析
快慢指针
参考代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
func hasCycle(head *ListNode) bool {
if head == nil || head.Next == nil {
return false
}
slow, fast := head, head
for fast != nil && fast.Next != nil {
slow = slow.Next
fast = fast.Next.Next
if slow == fast {
return true
}
}
return false
}
1
write your code here
相似题目
题目 | 难度 | 题解 |
---|---|---|
环形链表 II | Medium | |
快乐数 | Easy |
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用