MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Spiral Matrix/solution.py:12–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class Solution:
13 def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
14 if not matrix:
15 return []
16
17 start_row = 0
18 start_col = 0
19 end_row = len(matrix)
20 end_col = len(matrix[0])
21 output = []
22
23 while(start_row<end_row and start_col<end_col):
24 for i in range(start_col,end_col):
25 output.append(matrix[start_row][i])
26 start_row+=1
27
28 for j in range(start_row,end_row):
29 output.append(matrix[j][end_col-1])
30 end_col-=1
31
32 if(end_row<=start_row):
33 break
34
35 for k in range(end_col-1,start_col-1,-1):
36 output.append(matrix[end_row-1][k])
37 end_row-=1
38
39 if(end_col<=start_col):
40 break
41
42 for l in range(end_row-1,start_row-1,-1):
43 output.append(matrix[l][start_col])
44 start_col+=1
45
46 return output

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected