<doocs>0054.Spiral Matrix_1.py
def spiralOrder( matrix: List[List[int]]) -> List[int]:
    m, n = len(matrix), len(matrix[0])
    ans = []
    top, bottom, left, right = 0, m - 1, 0, n - 1
    while left <= right and top <= bottom:
        ans.extend([matrix[top][j] for j in range(left, right + 1)])
        ans.extend([matrix[i][right] for i in range(top + 1, bottom + 1)])
        if left < right and top < bottom:
            ans.extend([matrix[bottom][j] for j in range(right - 1, left - 1, -1)])
            ans.extend([matrix[i][left] for i in range(bottom - 1, top, -1)])
        top, bottom, left, right = top + 1, bottom - 1, left + 1, right - 1
    return ans
def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] :
    var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] )
    var_7 = [ ]
    var_8 , var_10 , var_11 , var_12 = 0 , var_4 - 1 , 0 , var_6 - 1
    while var_11 <= var_12 and var_8 <= var_10 :
        var_7.extend ( [ var_0 [ var_8 ] [ var_14 ] for var_14 in range ( var_11 , var_12 + 1 ) ] )
        var_7.extend ( [ var_0 [ var_16 ] [ var_12 ] for var_16 in range ( var_8 + 1 , var_10 + 1 ) ] )
        if var_11 < var_12 and var_8 < var_10 :
            var_7.extend ( [ var_0 [ var_10 ] [ var_14 ] for var_14 in range ( var_12 - 1 , var_11 - 1 , - 1 ) ] )
            var_7.extend ( [ var_0 [ var_16 ] [ var_11 ] for var_16 in range ( var_10 - 1 , var_8 , - 1 ) ] )
        var_8 , var_10 , var_11 , var_12 = var_8 + 1 , var_10 - 1 , var_11 + 1 , var_12 - 1
    return var_7
