@@ -0,0 +1,1111 @@
+public class Solution %7B%0A    public int%5B%5D%5B%5D generateMatrix(int n) %7B%0A        if(n == 0)%7B%0A            return new int%5B0%5D%5B0%5D;%0A        %7D%0A        int%5B%5D%5B%5D result = new int%5Bn%5D%5Bn%5D;%0A        int cur = 1, target = n*n;%0A        int up = 0, bottom = 0, left = 0, right = 0;%0A        while(true)%7B%0A            for(int i = left; i %3C n-right; i ++)%7B%0A                result%5Bup%5D%5Bi%5D = cur++;%0A            %7D%0A            up++;%0A            if(cur %3E target)%7B%0A                return result;%0A            %7D%0A            for(int i = up; i %3C n-bottom; i ++)%7B%0A                result%5Bi%5D%5Bn-right-1%5D = cur++;%0A            %7D%0A            right++;%0A            if(cur %3E target)%7B%0A                return result;%0A            %7D%0A            for(int i = n-right-1; i %3E= left; i --)%7B%0A                result%5Bn-bottom-1%5D%5Bi%5D = cur++;%0A            %7D%0A            bottom++;%0A            if(cur %3E target)%7B%0A                return result;%0A            %7D%0A            for(int i = n-bottom-1; i %3E= up; i --)%7B%0A                result%5Bi%5D%5Bleft%5D = cur++;%0A            %7D%0A            left++;%0A            if(cur %3E target)%7B%0A                return result;%0A            %7D%0A        %7D%0A    %7D%0A%7D

Q59 Spiral Matrix II