Python Solution and Tips


  • 0

    Draw lines and number those lines. You will find the pattern soon.

    The i-th can only cross i-3th, i-4th or i-5th on the first crossing.

    class Solution(object):
        def isSelfCrossing(self, x):
            """
            :type x: List[int]
            :rtype: bool
            """
            if len(x) < 4:
                return False
            for i in range(3, len(x)):
                if x[i] >= x[i-2] and x[i-1] <= x[i-3]:
                    return True
                if i >= 4 and x[i-1] == x[i-3] and x[i] + x[i-4] >= x[i-2]:
                    return True
                if i >= 5 and x[i-1] <= x[i-3] and x[i-3] <= x[i-1] + x[i-5] and x[i] + x[i-4] >= x[i-2] and x[i-4] <= x[i-2]:
                    return True
            return False
    

Log in to reply
 

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