Java solution


  • 0
    E
    
    public class Solution {
        public boolean isSelfCrossing(int[] x) {
            if (x.length < 4) return false;
            boolean mode = x[2] > x[0];
            for (int i = 3; i < x.length; i++) {
                if (!mode && x[i] >= x[i - 2]) return true;
                else if (mode && x[i] <= x[i - 2]) {
                    int l = (i >= 4) ? x[i - 4] : 0;
                    if (x[i] + l >= x[i - 2])
                        x[i - 1] -= x[i - 3];
                    mode = false;
                }
            }
            return false;
        }
    }
    

Log in to reply
 

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