摘要:
中序遍历 class Solution { int sum = 0; public TreeNode convertBST(TreeNode root) { inorder(root); return root; } /** * 按照右中左的顺序进行中序遍历 * 对中间的节点进行赋值 */ publ 阅读全文
posted @ 2022-02-24 13:36
振袖秋枫问红叶
阅读(28)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if (root == null){ return root; } /** * 如果根节点小于最小值,那其左子树肯定也小于最小值,那 阅读全文
posted @ 2022-02-24 13:13
振袖秋枫问红叶
阅读(29)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode insertIntoBST(TreeNode root, int val) { if (root == null){ return new TreeNode(val); } if (root.val > val){ ro 阅读全文
posted @ 2022-02-24 11:42
振袖秋枫问红叶
阅读(35)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { /** * 维护一个出现频率的最大值,如果频率等于最大值时就添加这个节点 * 如果频率大于这个最大值,就清除已有的节点,更新最大值(二叉搜索树中序遍历,节点是排好序的) * 要和前一个节点比较大小,需要一个prev指针 */ ArrayList<Int 阅读全文
posted @ 2022-02-24 10:50
振袖秋枫问红叶
阅读(24)
评论(0)
推荐(0)