| 10 | |
| 11 | |
| 12 | class 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 |
nothing calls this directly
no outgoing calls
no test coverage detected