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