Leetcode 270. Closest Binary Search Tree Value (cpp)
来源:互联网 发布:淘宝女装代销货源 编辑:程序博客网 时间:2024/04/30 01:58
Leetcode 270. Closest Binary Search Tree Value (cpp)
Tag: Tree, Binary Search
Difficulty: Easy
这是一道locked题目,给评论个“赞”呗?
/*270. Closest Binary Search Tree ValueGiven 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.*//** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int closestValue(TreeNode* root, double target) { int res = root->val; while(root != NULL) { if (abs(root->val - target) < abs(res - target)) { res = root->val; } if (root->val < target) { root = root->right; } else { root = root->left; } } return res; }};
0 0
- Leetcode 270. Closest Binary Search Tree Value (cpp)
- LeetCode 270. Closest Binary Search Tree Value
- Leetcode 272. Closest Binary Search Tree Value II (Hard) (cpp)
- [Leetcode]Closest Binary Search Tree Value II
- [Leetcode]Closest Binary Search Tree Value
- leetcode 270: Closest Binary Search Tree Value
- *LeetCode-Closest Binary Search Tree Value
- [leetcode 270] Closest Binary Search Tree Value
- Leetcode 270Closest Binary Search Tree Value
- LeetCode 270: Closest Binary Search Tree Value
- Leetcode 270 Closest Binary Search Tree Value
- [leetcode] 270. Closest Binary Search Tree Value 解题报告
- [Leetcode] 270. Closest Binary Search Tree Value 解题报告
- 270. Closest Binary Search Tree Value
- 270. Closest Binary Search Tree Value
- Closest Binary Search Tree Value
- Closest Binary Search Tree Value
- leetcode 272: Closest Binary Search Tree Value II
- node+express+ejs
- jsp贪吃蛇源码
- 深入浅出UML类图
- 2674 3-5 学生成绩统计
- win10 快捷键大全
- Leetcode 270. Closest Binary Search Tree Value (cpp)
- python初级教程:入门详解
- qt5.4.1(mingw) + opencv2.0.0 + win8安装过程
- gdb常用功能
- 汇编上机心得
- 清除浮动知识总结
- 标记
- Android 直接在子线程中创建Handler为什么会报错
- java中的Error和Exception