141. Linked List Cycle
确认linked list是否循环
思路:
快慢指针end
Python Code:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
slow = head
fast = head
while fast != None and fast.next != None:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False
今天75刷比较快 行有余力写一下每日 还好只是ez
快速解决