package leetcode;

/**
 * https://leetcode.com/problems/spiral-matrix-iii/
 */
public class Problem885 {
    public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem885 prob = new Problem885();
    }
}

@@ -177,132 +177,1183 @@
     
-// TODO
+int size = R * C;%0A        int%5B%5D%5B%5D result = new int%5Bsize%5D%5B2%5D;%0A        int count = 0;%0A        int index = 0;%0A        int row = r0;%0A        int col = c0;%0A        Direction direction = Direction.LEFT;%0A        result%5Bindex%5D%5B0%5D = row;%0A        result%5Bindex%5D%5B1%5D = col;%0A        index++;%0A        while (count %3C size) %7B%0A            if (withinBoundary(R, C, row, col)) %7B%0A                result%5Bindex%5D%5B0%5D = row;%0A                result%5Bindex%5D%5B1%5D = col;%0A                index++;%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private enum Direction %7B%0A        LEFT, DOWN, RIGHT, UP
 %0A    
+%7D%0A%0A
     
-return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem885 prob = new Problem885();
+private static boolean withinBoundary(int maxRow, int maxCol, int row, int col) %7B%0A        return !(row %3C 0 %7C%7C row %3E= maxRow %7C%7C col %3C 0 %7C%7C col %3E= maxCol);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem885 prob = new Problem885();%0A        System.out.println(prob.spiralMatrixIII(1, 4, 0, 0)); // %5B%5B0,0%5D,%5B0,1%5D,%5B0,2%5D,%5B0,3%5D%5D%0A        System.out.println(prob.spiralMatrixIII(5, 6, 1, 4)); // %5B%5B1,4%5D,%5B1,5%5D,%5B2,5%5D,%5B2,4%5D,%5B2,3%5D,%5B1,3%5D,%5B0,3%5D,%5B0,4%5D,%5B0,5%5D,%5B3,5%5D,%5B3,4%5D,%5B3,3%5D,%5B3,2%5D,%5B2,2%5D,%5B1,2%5D,%5B0,2%5D,%5B4,5%5D,%5B4,4%5D,%5B4,3%5D,%5B4,2%5D,%5B4,1%5D,%5B3,1%5D,%5B2,1%5D,%5B1,1%5D,%5B0,1%5D,%5B4,0%5D,%5B3,0%5D,%5B2,0%5D,%5B1,0%5D,%5B0,0%5D%5D
 %0A   

Update problem 885