diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md index 442ea8fb..8b9e1f6d 100644 --- a/problems/0669.修剪二叉搜索树.md +++ b/problems/0669.修剪二叉搜索树.md @@ -242,25 +242,22 @@ public: Java: -```java + +```Java class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { - root = trim(root,low,high); - return root; - } - - private static TreeNode trim(TreeNode root,int low, int high) { - if (root == null ) return null; + if (root == null) { + return null; + } if (root.val < low) { - return trim(root.right,low,high); + return trimBST(root.right, low, high); } if (root.val > high) { - return trim(root.left,low,high); + return trimBST(root.left, low, high); } - - root.left = trim(root.left,low,high); - root.right = trim(root.right,low,high); - + // root在[low,high]范围内 + root.left = trimBST(root.left, low, high); + root.right = trimBST(root.right, low, high); return root; } }