<s> """<STR_LIT>""" <EOL> import sys <EOL> __author__ = '<STR_LIT>' <EOL> class TreeNode ( object ) : <EOL> def __init__ ( self , x ) : <EOL> self . val = x <EOL> self . left = None <EOL> self . right = None <EOL> class Solution ( object ) : <EOL> def closestValue ( self , root , target ) : <EOL> """<STR_LIT>""" <EOL> lo = [ - sys . float_info . max ] <EOL> self . find ( root , target , lo , True ) <EOL> hi = [ sys . float_info . max ] <EOL> self . find ( root , target , hi , False ) <EOL> if hi [ <NUM_LIT:0> ] - target < target - lo [ <NUM_LIT:0> ] : <EOL> return int ( hi [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return int ( lo [ <NUM_LIT:0> ] ) <EOL> def find ( self , root , target , ret , lower = True ) : <EOL> if not root : <EOL> return <EOL> if root . val == target : <EOL> ret [ <NUM_LIT:0> ] = root . val <EOL> return <EOL> if root . val < target : <EOL> if lower : ret [ <NUM_LIT:0> ] = max ( ret [ <NUM_LIT:0> ] , root . val ) <EOL> self . find ( root . right , target , ret , lower ) <EOL> else : <EOL> if not lower : ret [ <NUM_LIT:0> ] = min ( ret [ <NUM_LIT:0> ] , root . val ) <EOL> self . find ( root . left , target , ret , lower ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> assert Solution ( ) . closestValue ( TreeNode ( <NUM_LIT> ) , <NUM_LIT:0.0> ) == <NUM_LIT> </s>
