@@ -0,0 +1,1583 @@
+/***%0A * Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.%0A *%0A * For example,%0A * Given the following matrix:%0A *%0A * %5B%0A *  %5B 1, 2, 3 %5D,%0A *  %5B 4, 5, 6 %5D,%0A *  %5B 7, 8, 9 %5D%0A * %5D%0A * You should return %5B1,2,3,6,9,8,7,4,5%5D.%0A */%0Aimport java.util.List;%0Aimport java.util.ArrayList;%0A%0Apublic class Solution %7B%0A    // Solution 1: O(m * n) O(1)%0A    public List%3CInteger%3E spiralOrder(int%5B%5D%5B%5D matrix) %7B%0A        List%3CInteger%3E ret = new ArrayList%3CInteger%3E();%0A        if (matrix == null %7C%7C matrix.length == 0)%0A            return ret;%0A%0A        int m = matrix.length;%0A        int n = matrix%5B0%5D.length;%0A%0A        int x = 0;%0A        int y = 0;%0A%0A        while(m %3E 0 && n %3E 0) %7B%0A            if (m == 1) %7B%0A                for (int i = 0; i %3C n; i++)%0A                    ret.add(matrix%5Bx%5D%5By++%5D;%0A                break;%0A            %7D else if (n == 1) %7B%0A                for (int j = 0; j %3C m; j++)%0A                    ret.add(matrix%5Bx++%5D%5By%5D);%0A                break;%0A            %7D%0A            // top - move right%0A            for (int i = 0; i %3C n - 1; i++)%0A                ret.add(matrix%5Bx%5D%5By++%5D);%0A            // right - move down%0A            for (int j = 0; j %3C m - 1; j++)%0A                ret.add(matrix%5Bx++%5D%5By%5D);%0A            // bottom - move left%0A            for (int i = 0; i %3C n - 1; i++)%0A                ret.add(matrix%5Bx%5D%5By--%5D);%0A            // left - move up%0A            for (int j = 0; j %3C m - 1; j--)%0A                ret.add(matrix%5Bx--%5D%5By%5D);%0A            x++;%0A            y++;%0A            m -= 2;%0A            n-= 2;%0A        %7D%0A        return ret;%0A    %7D%0A    %0A%7D%0A

add SpiralMatrix.java