Simple Python solution!


  • 5
    P
    class Solution(object):
        def hasCycle(self, head):
            """
            :type head: ListNode
            :rtype: bool
            """
            slow = head
            fast = head
            while fast is not None and fast.next is not None:
                fast = fast.next.next
                slow = slow.next
                if fast == slow:
                    return True
            return False

  • 0
    W

    nice solution!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.