
(图片来源https://leetcode-cn.com/problems/linked-list-cycle/
)
日期 | 是否一次通过 | comment |
---|---|---|
2020-03-17 | 0 |
递归
public boolean hasCycle(ListNode pHead) {
if(pHead == null || pHead.next == null) {
return false;
}
ListNode pSlow = pHead;
ListNode pFast = pHead;
while(pFast != null && pFast.next != null) {
pSlow = pSlow.next;
pFast = pFast.next.next;
if(pSlow == pFast) {
return true;
}
}
return false;
}
网友评论