File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -598,5 +598,30 @@ object Solution {
598
598
}
599
599
}
600
600
```
601
+ C#:
602
+ ``` csharp
603
+ public class Solution {
604
+ public int [][] GenerateMatrix (int n ) {
605
+ int [][] answer = new int [n ][];
606
+ for (int i = 0 ; i < n ; i ++ )
607
+ answer [i ] = new int [n ];
608
+ int start = 0 ;
609
+ int end = n - 1 ;
610
+ int tmp = 1 ;
611
+ while (tmp < n * n )
612
+ {
613
+ for (int i = start ; i < end ; i ++ ) answer [start ][i ] = tmp ++ ;
614
+ for (int i = start ; i < end ; i ++ ) answer [i ][end ] = tmp ++ ;
615
+ for (int i = end ; i > start ; i -- ) answer [end ][i ] = tmp ++ ;
616
+ for (int i = end ; i > start ; i -- ) answer [i ][start ] = tmp ++ ;
617
+ start ++ ;
618
+ end -- ;
619
+ }
620
+ if (n % 2 == 1 ) answer [n / 2 ][n / 2 ] = tmp ;
621
+ return answer ;
622
+ }
623
+ }
624
+ ```
625
+
601
626
-----------------------
602
627
<div align =" center " ><img src =https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width =500 > </img ></div >
You can’t perform that action at this time.
0 commit comments