[LeetCode] 141. Linked List Cycle 单链表判圆算法
生活随笔
收集整理的這篇文章主要介紹了
[LeetCode] 141. Linked List Cycle 单链表判圆算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TWO POINTER
快指針速度2 , 慢指針速度1
相對速度1,有環必然相遇
public class Solution {public boolean hasCycle(ListNode head) {ListNode fast = head,slow = head;while(fast!=null && fast.next!=null){slow = slow.next;fast = fast.next.next;if(slow == fast){return true;}}return false;} }?
轉載于:https://www.cnblogs.com/Poceer/p/10954550.html
總結
以上是生活随笔為你收集整理的[LeetCode] 141. Linked List Cycle 单链表判圆算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谷歌浏览器显示弹框登陆代理解决方法
- 下一篇: 透视校正