My Python Code (Two Pointers, Different Steps)


  • 1
    R
    class Solution(object):
        def hasCycle(self, head):
            """
            :type head: ListNode
            :rtype: bool
            """
            if not head:
                return False
                
            pt1, pt2 = head, head
            while pt2.next and pt2.next.next:
                pt2 = pt2.next.next
                pt1 = pt1.next
                if pt2 == pt1:
                    return True
                
            return False
    

Log in to reply
 

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