Simple python, easy to userstand


  • 0
    class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head:return False
        p,q=head,head
        while p and q:
            if p.next:p=p.next
            else: break
            if q.next and q.next.next:q=q.next.next
            else:break
            if p==q:return True
        return False

Log in to reply
 

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