C Simple Solution


  • 0
    P
    bool isSelfCrossing(int* x, int xSize)
    {
        int i = 2, j = 0;
        
        while(i < xSize && x[i] > x[j])
        {
            i++;
            j++;
        }
        
        j = i + 1;
        
        if(j >= xSize) return false;
        
        if(x[i] < x[i - 2] - (i > 3 ? x[i - 4] : 0) ? x[j] < x[i - 1]
             : x[j] < x[i - 1] - (i > 2 ? x[i - 3] : 0))
        {
            j++;
            
            while(j < xSize && x[i] > x[j])
            {
                i++;
                j++;
            }
            
            return j < xSize;
        }
        
        return true;
    }
    

Log in to reply
 

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