标签:roo problem bin uri trim bad span nod strong
669. 修剪二叉搜索树
669. Trim a Binary Search Tree
题目描述
LeetCode669. Trim a Binary Search Tree简单
Java 实现
TreeNode Class
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
class Solution {
public TreeNode trimBST(TreeNode root, int L, int R) {
if (root == null) {
return null;
}
if (root.val < L) {
return trimBST(root.right, L, R);
}
if (root.val > R) {
return trimBST(root.left, L, R);
}
root.left = trimBST(root.left, L, R);
root.right = trimBST(root.right, L, R);
return root;
}
}
参考资料
LeetCode 669. 修剪二叉搜索树(Trim a Binary Search Tree)
标签:roo problem bin uri trim bad span nod strong
原文地址:https://www.cnblogs.com/hglibin/p/10994693.html