Cheat solution beats 99%


  • 0

    I used a tricky solution, which is unstable, but beat 99%.
    Change values to a randomized number and if the value occurs a second time, it means a loop.
    The potential error is you choose a number which already exists in a list, by choosing a randomized number from a wider range, you can minimize this probability.

    class Solution(object):
        def hasCycle(self, head):
            while head:
                if head.val == 31415926:
                    return True
                head.val = 31415926
                head = head.next
            return False
    

  • 0
    S

    这个好像是面包屑方法。在深林里迷了路,在路上丢面包屑做标记,当再次看到面包屑时说明自己又绕回来了 haha


Log in to reply
 

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