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
快速解決