My Python Code (Two Pointers, Different Steps)

  • 1
    class Solution(object):
        def hasCycle(self, head):
            :type head: ListNode
            :rtype: bool
            if not head:
                return False
            pt1, pt2 = head, head
            while and
                pt2 =
                pt1 =
                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.