Skip to content

Commit efeedce

Browse files
authored
Create Solution.py
1 parent 5cb92a1 commit efeedce

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class Solution:
2+
def rotateCCW(self, Matrix):
3+
"""
4+
:type Matrix: list[list[int]]
5+
:rtype Mat2: list[list[int]]
6+
7+
This function IGNORES THE 1st ROW of
8+
the Matrix & rotates remaining elements
9+
in CounterClockWise direction
10+
11+
Example:
12+
if Matrix = [ [0, 1, 2, 3],
13+
[4, 5, 6, 7],
14+
[8, 9, 10, 11]]
15+
16+
then Mat2 = [ [7, 11],
17+
[6, 10],
18+
[5, 9],
19+
[4, 8]]
20+
"""
21+
22+
M = len(Matrix)
23+
N = len(Matrix[0])
24+
Mat2 = [[0]*(M-1) for x in range(N)]
25+
26+
for i in range(N-1, -1, -1):
27+
for j in range(1, M):
28+
Mat2[N-1-i][j-1] = Matrix[j][i]
29+
30+
return Mat2
31+
32+
def spiralOrder(self, Matrix):
33+
"""
34+
:type Matrix: list[list[int]]
35+
:rtype Result: list[int]
36+
"""
37+
38+
Result = []
39+
while len(Matrix) > 0:
40+
for i in Matrix[0]:
41+
Result.append(i)
42+
43+
Matrix = self.rotateCCW(Matrix)
44+
45+
return Result

0 commit comments

Comments
 (0)