Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def closestValue(self, root: TreeNode, target: float) -> int:
- best = float('inf')
- while root:
- if abs(target - root.val) < abs(target - best):
- best = root.val
- if root.val > target:
- root = root.left
- elif root.val < target:
- root = root.right
- else:
- break
- return best
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement