<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class Solution : <EOL> def restoreIpAddresses ( self , s ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> self . dfs ( s , [ ] , result ) <EOL> return result <EOL> def dfs_complicated ( self , seq , cur , result ) : <EOL> """<STR_LIT>""" <EOL> if len ( cur ) > <NUM_LIT:4> : <EOL> return <EOL> if not cur or self . is_valid ( cur [ - <NUM_LIT:1> ] ) : <EOL> if len ( cur ) == <NUM_LIT:4> and not seq : <EOL> result . append ( "<STR_LIT:.>" . join ( cur ) ) <EOL> return <EOL> for i in xrange ( <NUM_LIT:1> , min ( <NUM_LIT:3> , len ( seq ) ) + <NUM_LIT:1> ) : <EOL> self . dfs ( seq [ i : ] , cur + [ seq [ : i ] ] , result ) <EOL> def dfs ( self , seq , cur , result ) : <EOL> """<STR_LIT>""" <EOL> if not seq and len ( cur ) == <NUM_LIT:4> : <EOL> result . append ( "<STR_LIT:.>" . join ( cur ) ) <EOL> return <EOL> for i in xrange ( <NUM_LIT:1> , min ( <NUM_LIT:3> , len ( seq ) ) + <NUM_LIT:1> ) : <EOL> new_seg = seq [ : i ] <EOL> if len ( cur ) < <NUM_LIT:4> and self . is_valid ( new_seg ) : <EOL> self . dfs ( seq [ i : ] , cur + [ new_seg ] , result ) <EOL> else : <EOL> return <EOL> def is_valid ( self , s ) : <EOL> if not s : <EOL> return False <EOL> return s == "<STR_LIT:0>" or s [ <NUM_LIT:0> ] != "<STR_LIT:0>" and <NUM_LIT:0> <= int ( s ) < <NUM_LIT> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> IP = "<STR_LIT>" <EOL> print Solution ( ) . restoreIpAddresses ( IP ) </s>
