@@ -0,0 +1,1685 @@
+/**%0A * You are given an array x of n positive numbers. You start at point (0,0) and moves x%5B0%5D metres to the north, then%0A * x%5B1%5D metres to the west, x%5B2%5D metres to the south, x%5B3%5D metres to the east and so on. In other words, after each%0A * move your direction changes counter-clockwise.%0A *%0A * Write a one-pass algorithm with O(1) extra space to determine, if your path crosses itself, or not.%0A *%0A * Example 1:%0A * Given x = %5B2, 1, 1, 2%5D,%0A * %E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A * %E2%94%82   %E2%94%82%0A * %E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%3E%0A *     %E2%94%82%0A *%0A * Return true (self crossing)%0A *%0A * Example 2:%0A * Given x = %5B1, 2, 3, 4%5D,%0A * %E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A * %E2%94%82      %E2%94%82%0A * %E2%94%82%0A * %E2%94%82%0A * %E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%3E%0A *%0A * Return false (not self crossing)%0A *%0A * Example 3:%0A * Given x = %5B1, 1, 1, 1%5D,%0A * %E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A * %E2%94%82   %E2%94%82%0A * %E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%3E%0A *%0A * Return true (self crossing)%0A *%0A * Tags: Math%0A */%0Apublic class SelfCrossing %7B%0A    public boolean isSelfCrossing(int%5B%5D x) %7B%0A        for (int i = 3; i %3C x.length; i++) %7B%0A            if (x%5Bi%5D %3E= x%5Bi - 2%5D && x%5Bi - 1%5D %3C= x%5Bi - 3%5D) %7B%0A                // checks if current line crosses the line 3 steps ahead of it%0A                return true;%0A            %7D%0A            if (i %3E= 4) %7B%0A                // checks if current line crosses the line 4 steps ahead of it%0A                if (x%5Bi - 1%5D == x%5Bi - 3%5D && x%5Bi%5D + x%5Bi - 4%5D %3E= x%5Bi - 2%5D) %7B%0A                    return true;%0A                %7D%0A            %7D%0A            if (i %3E= 5) %7B%0A                // checks if current line crosses the line 6 steps ahead of it%0A                if (x%5Bi - 2%5D - x%5Bi - 4%5D %3E= 0 && x%5Bi%5D %3E= x%5Bi - 2%5D - x%5Bi - 4%5D && x%5Bi - 1%5D %3E= x%5Bi - 3%5D - x%5Bi - 5%5D%0A                    && x%5Bi - 1%5D %3C= x%5Bi - 3%5D) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A

add 335 Self Crossing