Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5819903

Browse files
committed
add 059 array
1 parent 6c69294 commit 5819903

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎LeetCodeSolutions/059.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#==================================================
2+
#==> Title: 59. 螺旋矩阵 II
3+
#==> Author: Zhang zhen
4+
#==> Email: hustmatnoble.gmail.com
5+
#==> GitHub: https://github.com/MatNoble
6+
#==> Date: 2/1/2021
7+
#==================================================
8+
9+
"""
10+
https://leetcode-cn.com/problems/spiral-matrix-ii/
11+
"""
12+
13+
from typing import List
14+
class Solution:
15+
def generateMatrix(self, n: int) -> List[List[int]]:
16+
i = j = 0
17+
k = c = 1
18+
res = [[0]*n for i in range(n)]
19+
while k < n*n:
20+
while j < n-c:
21+
res[i][j] = k
22+
k += 1
23+
j += 1
24+
while i < n-c:
25+
res[i][j] = k
26+
k += 1
27+
i += 1
28+
while j > c-1:
29+
res[i][j] = k
30+
k += 1
31+
j -= 1
32+
while i > c-1:
33+
res[i][j] = k
34+
k += 1
35+
i -= 1
36+
i += 1
37+
j += 1
38+
c += 1
39+
if k == n*n: res[i][i] = k
40+
return res
41+
42+
mat = Solution()
43+
n = 7
44+
# n = 1
45+
mat.generateMatrix(n)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /