Skip to content

Commit eb3eb33

Browse files
authored
Update 0059.螺旋矩阵II.md
1 parent a29b52c commit eb3eb33

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

problems/0059.螺旋矩阵II.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,5 +598,30 @@ object Solution {
598598
}
599599
}
600600
```
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+
601626
-----------------------
602627
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
 (0)