@@ -0,0 +1,1306 @@
+package leetcode.spiral_matrix_ii;%0A%0A%0Apublic class Solution %7B%0A    public int%5B%5D%5B%5D generateMatrix(int n) %7B%0A    %09int%5B%5D%5B%5D ans = new int%5Bn%5D%5Bn%5D;%0A    %09if(n == 0) return ans;%0A    %09int height = n;%0A    %09int width = n;%0A    %09int number = 1;%0A        int x = 0, y = 0;%0A        ans%5B0%5D%5B0%5D = number++;%0A        int boundl = -1, boundr = width;%0A        int boundu = -1, boundd = height;%0A        while(boundl %3C= boundr && boundu %3C= boundd)%7B%0A        %09while(y + 1 %3C boundr)%7B%0A        %09%09ans%5Bx%5D%5By + 1%5D = number++;%0A        %09%09y++;%0A        %09%7D%0A        %09boundu++;%0A        %09if(boundu + 1 == boundd) break;%0A        %09while(x + 1 %3C boundd)%7B%0A        %09%09ans%5Bx + 1%5D%5By%5D = number++;%0A        %09%09x++;%0A        %09%7D%0A        %09boundr--;%0A        %09if(boundr - 1 == boundl) break;%0A        %09while(y - 1 %3E boundl)%7B%0A        %09%09ans%5Bx%5D%5By - 1%5D = number++;%0A        %09%09y--;%0A        %09%7D%0A        %09boundd--;%0A        %09if(boundd - 1 == boundu) break;%0A        %09while(x - 1 %3E boundu)%7B%0A        %09%09ans%5Bx - 1%5D%5By%5D = number++;%0A        %09%09x--;%0A        %09%7D%0A        %09boundl++;%0A        %09if(boundl + 1 == boundr) break;%0A        %7D%0A    %09return ans;%0A    %7D%0A    %0A    public static void main(String%5B%5D args)%7B%0A    %09int%5B%5D%5B%5D ans = new Solution().generateMatrix(10);%0A    %09for(int%5B%5D x : ans)%7B%0A    %09%09for(int y : x)%7B%0A    %09%09%09System.err.print(y + %22 %22);%0A    %09%09%7D%0A    %09%09System.err.println(%22%22);%0A    %09%7D%0A    %7D%0A%7D%0A

Add java solution for 59. Spiral Matrix II