-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleet_0054_spiral_matrix__OLD.py
53 lines (52 loc) · 1.29 KB
/
leet_0054_spiral_matrix__OLD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
hicol = len(matrix[0])
hirow = len(matrix)
area = hicol * hirow
if area is 1:
return matrix[0]
locol = -1
lorow = -1
count = 0
r = 0
c = 0
g = []
while True:
if count is not 0:
c += 1
while c < hicol:
g.append(matrix[r][c])
count += 1
c += 1
if count is area:
break
c -= 1
r += 1
while r < hirow:
g.append(matrix[r][c])
count += 1
r += 1
if count is area:
break
r -= 1
c -= 1
while c > locol:
g.append(matrix[r][c])
count += 1
c -= 1
if count is area:
break
c += 1
r -= 1
hirow -= 1
hicol -= 1
lorow += 1
locol += 1
while r > lorow:
g.append(matrix[r][c])
count += 1
r -= 1
if count is area:
break
r += 1
return g