-
Couldn't load subscription status.
- Fork 3
添加669. 修剪二叉搜索树的Java版代码 #1186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
添加669. 修剪二叉搜索树的Java版代码 #1186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a Java implementation for LeetCode problem 669 (Trim a Binary Search Tree). The solution uses an iterative approach to trim nodes that fall outside the specified [low, high] range while maintaining the BST structure.
Key changes:
- Implements a three-phase iterative algorithm: finding a valid root node, trimming the left subtree, and trimming the right subtree
- Uses a while-loop based approach rather than recursion
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,50 @@ | |||
| import javax.swing.tree.TreeNode; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实去掉或者注释掉会更好一些呢
| class Solution { | ||
| public TreeNode trimBST(TreeNode root, int low, int high) { | ||
| //寻找新的根节点 | ||
| while(root!=null && (root.val<low || root.val>high)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果再多一些空格,格式就更好看啦
|
hi~ 非常感谢大佬提供的0699的Java版本的代码! 不过在review时还是有两个小建议,如果这样的话效果应该会更好一点 |
我来处理一下吧 |
哈哈哈好的,我也是BUPT的,这是完成老师的一个实验(尝试提交一个PR) |
|
哈哈哈好的,已经合并了 也欢迎校友的继续参与嗷 [Doge] |
No description provided.