Leetcode 270Closest Binary Search Tree Value

来源:互联网 发布:ping端口号 编辑:程序博客网 时间:2024/05/17 05:01

Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.

Note: Given target value is a floating point. You are guaranteed to have only one unique value in the BST that is closest to the target.

Analysis:

这个题可以用二叉树的性质,每次排除掉树的一半节点,然后判断是children的小还是当前节点小。

Leetcode中BFS的性质

0 0