# @lc code=start classSolution: defspiralOrder(self, matrix: List[List[int]]) -> List[int]: ifnot matrix: returnlist() res = list() rows, columns = len(matrix), len(matrix[0]) left, right, top, bottom = 0, columns - 1, 0, rows - 1 while left<=right and top<=bottom: for column inrange(left, right+1): res.append(matrix[top][column]) for row inrange(top+1, bottom+1): res.append(matrix[row][right])
if left < right and top < bottom: for column inrange(right-1, left, -1): res.append(matrix[bottom][column]) for row inrange(bottom, top, -1): res.append(matrix[row][left])