class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
if None == head or None == head.next:
return False
pfast = head
pslow = head
while pfast and pfast.next:
pfast = pfast.next.next
pslow = pslow.next
if pfast == pslow:
return True
return False
这个题是很经典的题,要我说什么,我也说不出什么,只是觉得这种算法(想法)和nb,仅此而已。
【leetcode】Linked List Cycle (python)
最新推荐文章于 2021-05-28 20:16:14 发布