leetcode669
作者:互联网
二叉树的题目无脑递归做,关键还是在三板斧——确定参数和返回值、终止条件和单层逻辑体
public TreeNode trimBST(TreeNode root, int low, int high) {
if(root == null) return null;
if(root.val < low) {
if(root.right != null) return trimBST(root.right, low, high);
else return null;
}
if(root.val > high) {
if(root.left != null) return trimBST(root.left, low, high);
else return null;
}
root.left = trimBST(root.left, low, high);
root.right = trimBST(root.right, low, high);
return root;
}
标签:return,high,leetcode669,trimBST,null,root,low 来源: https://www.cnblogs.com/huangming-zzz/p/16159025.html