<s> class Solution ( object ) : <EOL> def longestIncreasingPath ( self , matrix ) : <EOL> """<STR_LIT>""" <EOL> if not matrix : <EOL> return <NUM_LIT:0> <EOL> def longestpath ( matrix , i , j , max_lengths ) : <EOL> if max_lengths [ i ] [ j ] : <EOL> return max_lengths [ i ] [ j ] <EOL> max_depth = <NUM_LIT:0> <EOL> directions = [ ( <NUM_LIT:0> , - <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( - <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ] <EOL> for d in directions : <EOL> x , y = i + d [ <NUM_LIT:0> ] , j + d [ <NUM_LIT:1> ] <EOL> if <NUM_LIT:0> <= x < len ( matrix ) and <NUM_LIT:0> <= y < len ( matrix [ <NUM_LIT:0> ] ) and matrix [ x ] [ y ] < matrix [ i ] [ j ] : <EOL> max_depth = max ( max_depth , longestpath ( matrix , x , y , max_lengths ) ) ; <EOL> max_lengths [ i ] [ j ] = max_depth + <NUM_LIT:1> <EOL> return max_lengths [ i ] [ j ] <EOL> res = <NUM_LIT:0> <EOL> max_lengths = [ [ <NUM_LIT:0> for _ in xrange ( len ( matrix [ <NUM_LIT:0> ] ) ) ] for _ in xrange ( len ( matrix ) ) ] <EOL> for i in xrange ( len ( matrix ) ) : <EOL> for j in xrange ( len ( matrix [ <NUM_LIT:0> ] ) ) : <EOL> res = max ( res , longestpath ( matrix , i , j , max_lengths ) ) <EOL> return res </s>
