@@ -0,0 +1,975 @@
+// Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.%0A%0A// For example,%0A// Given n = 3,%0A%0A// You should return the following matrix:%0A// %5B%0A//  %5B 1, 2, 3 %5D,%0A//  %5B 8, 9, 4 %5D,%0A//  %5B 7, 6, 5 %5D%0A// %5D%0A%0Apublic class Solution %7B%0A    public int%5B%5D%5B%5D generateMatrix(int n) %7B%0A%09%09int%5B%5D%5B%5D m = new int%5Bn%5D%5Bn%5D;%0A%0A%09%09if(n == 0) return m;%0A%0A%09%09int startRowCol = 0;%0A%09%09int endRowCol = n - 1;%0A%09%09int counter = 1;%0A%0A%09%09while(startRowCol %3C= endRowCol)%7B%0A%09%09%09if(startRowCol == endRowCol)%7B%0A%09%09%09%09m%5BstartRowCol%5D%5BstartRowCol%5D = counter;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%0A%09%09%09for(int i = startRowCol; i %3C endRowCol; i++)%7B%0A%09%09%09%09m%5BstartRowCol%5D%5Bi%5D = counter++;%0A%09%09%09%7D%0A%0A%09%09%09for(int i = startRowCol; i %3C endRowCol; i++)%7B%0A%09%09%09%09m%5Bi%5D%5BendRowCol%5D = counter++;%0A%09%09%09%7D%0A%0A%09%09%09for(int i = endRowCol; i %3E startRowCol; i--)%7B%0A%09%09%09%09m%5BendRowCol%5D%5Bi%5D = counter++;%0A%09%09%09%7D%0A%0A%09%09%09for(int i = endRowCol; i %3E startRowCol; i--)%7B%0A%09%09%09%09m%5Bi%5D%5BstartRowCol%5D = counter++;%0A%09%09%09%7D%0A%0A%09%09%09startRowCol++;%0A%09%09%09endRowCol--;%0A%09%09%7D     %0A%0A%09%09return m;%0A    %7D%0A%7D%0A%0A

add spiral matrix ii solution