my O(1) space solution in Python


  • 0
    M

    class Solution(object):

    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head: return False
        slow,fast=head,head.next
        while slow is not fast and fast and fast.next:
            slow=slow.next
            fast=fast.next.next
        if slow is fast: return True
        return False

Log in to reply
 

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