A method without using two pointers


  • 0
    Z

    Am I the only one came out with this cheated method?
    I use a 'sign' to sign the nodes I have passed. The dangerous thing is that there is any node's value equals to my 'sign', so I make it strange :D

    class Solution(object):
        def hasCycle(self, head):
            """
            :type head: ListNode
            :rtype: bool
            """
            while head:
                if head.val=='signed!':
                    return True
                head.val = 'signed!'
                head = head.next
            return False
    

Log in to reply
 

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