<s> class Solution : <EOL> def spiralOrder ( self , matrix ) : <EOL> result = [ ] <EOL> if matrix == [ ] : <EOL> return result <EOL> left , right , top , bottom = <NUM_LIT:0> , len ( matrix [ <NUM_LIT:0> ] ) - <NUM_LIT:1> , <NUM_LIT:0> , len ( matrix ) - <NUM_LIT:1> <EOL> while left <= right and top <= bottom : <EOL> for j in xrange ( left , right + <NUM_LIT:1> ) : <EOL> result . append ( matrix [ top ] [ j ] ) <EOL> for i in xrange ( top + <NUM_LIT:1> , bottom ) : <EOL> result . append ( matrix [ i ] [ right ] ) <EOL> for j in reversed ( xrange ( left , right + <NUM_LIT:1> ) ) : <EOL> if top < bottom : <EOL> result . append ( matrix [ bottom ] [ j ] ) <EOL> for i in reversed ( xrange ( top + <NUM_LIT:1> , bottom ) ) : <EOL> if left < right : <EOL> result . append ( matrix [ i ] [ left ] ) <EOL> left , right , top , bottom = left + <NUM_LIT:1> , right - <NUM_LIT:1> , top + <NUM_LIT:1> , bottom - <NUM_LIT:1> <EOL> return result <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print Solution ( ) . spiralOrder ( [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] ] ) <EOL> print Solution ( ) . spiralOrder ( [ [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) </s>
