@@ -0,0 +1,2037 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * https://leetcode.com/problems/spiral-matrix/%0A */%0Apublic class Problem54 %7B%0A    public List%3CInteger%3E spiralOrder(int%5B%5D%5B%5D matrix) %7B%0A        List%3CInteger%3E result = new ArrayList%3C%3E();%0A        if (matrix.length == 0) %7B%0A            return result;%0A        %7D%0A        Direction%5B%5D directions = new Direction%5B%5D%7B%0A            Direction.LEFT, Direction.DOWN, Direction.RIGHT, Direction.UP%0A        %7D;%0A        int dirIdx = 0;%0A        int row = 0;%0A        int col = 0;%0A        int rowBegin = 0;%0A        int colBegin = 0;%0A        int rowEnd = matrix.length;%0A        int colEnd = matrix%5Brow%5D.length;%0A        do %7B%0A            if (dirIdx == directions.length) %7B%0A                dirIdx = 0;%0A            %7D%0A            switch (directions%5BdirIdx%5D) %7B%0A            case LEFT:%0A                row = rowBegin;%0A                col = colBegin;%0A                while (col %3C colEnd) %7B%0A                    result.add(matrix%5Brow%5D%5Bcol%5D);%0A                    col++;%0A                %7D%0A                rowBegin++;%0A                col--;%0A                break;%0A            case DOWN:%0A                row++;%0A                while (row %3C rowEnd) %7B%0A                    result.add(matrix%5Brow%5D%5Bcol%5D);%0A                    row++;%0A                %7D%0A                colEnd--;%0A                row--;%0A                break;%0A            case RIGHT:%0A                col--;%0A                while (col %3E= colBegin) %7B%0A                    result.add(matrix%5Brow%5D%5Bcol%5D);%0A                    col--;%0A                %7D%0A                rowEnd--;%0A                col++;%0A                break;%0A            case UP:%0A                row--;%0A                while (row %3E= rowBegin) %7B%0A                    result.add(matrix%5Brow%5D%5Bcol%5D);%0A                    row--;%0A                %7D%0A                colBegin++;%0A                break;%0A            %7D%0A            dirIdx++;%0A        %7D while (rowBegin != rowEnd && colBegin != colEnd);%0A        return result;%0A    %7D%0A%0A    private static enum Direction %7B%0A        LEFT, RIGHT, UP, DOWN%0A    %7D%0A%7D%0A

Solve problem 54