@@ -0,0 +1,1147 @@
+public class Solution %7B%0A    public List%3CInteger%3E spiralOrder(int%5B%5D%5B%5D matrix) %7B%0A        int up = 0, bottom = 0, left = 0, right = 0;%0A        List%3CInteger%3E result = new ArrayList%3CInteger%3E();%0A        if(matrix.length == 0 %7C%7C matrix%5B0%5D.length == 0)%7B%0A            return result;%0A        %7D%0A        int m = matrix.length, n = matrix%5B0%5D.length;%0A        while(true)%7B%0A            for(int i = left; i %3C n-right; i ++)%7B%0A                result.add(matrix%5Bup%5D%5Bi%5D);%0A            %7D%0A            if(++up + bottom %3E= m)%7B%0A                return result;%0A            %7D%0A            for(int i = up; i %3C m-bottom; i ++)%7B%0A                result.add(matrix%5Bi%5D%5Bn-right-1%5D);%0A            %7D%0A            if(++right + left %3E= n)%7B%0A                return result;%0A            %7D%0A            for(int i = n-right-1; i %3E= left; i--)%7B%0A                result.add(matrix%5Bm-bottom-1%5D%5Bi%5D);%0A            %7D%0A            if(++bottom + up %3E= m)%7B%0A                return result;%0A            %7D%0A            for(int i = m-bottom-1; i %3E= up; i--)%7B%0A                result.add(matrix%5Bi%5D%5Bleft%5D);%0A            %7D%0A            if(++left + right %3E= n)%7B%0A                return result;%0A            %7D%0A        %7D%0A    %7D%0A%7D

Q54 Spiral Matrix