|
|
|
@ -16,7 +16,7 @@ |
|
|
|
|
10. [37. 序列化二叉树](https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof/) |
|
|
|
|
11. [28. 对称的二叉树](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) |
|
|
|
|
12. [33. 二叉搜索树的后序遍历序列](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) |
|
|
|
|
13. [Offer 36. 二叉搜索树与双向链表](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/) |
|
|
|
|
13. [36. 二叉搜索树与双向链表](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/) |
|
|
|
|
|
|
|
|
|
#### [07. 重建二叉树](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) |
|
|
|
|
|
|
|
|
@ -552,3 +552,47 @@ class Solution { |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
#### [Offer 54. 二叉搜索树的第k大节点](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) |
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
class Solution { |
|
|
|
|
List<Integer> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
public int kthLargest(TreeNode root, int k) { |
|
|
|
|
helper(root); |
|
|
|
|
return list.get(list.size() - k); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void helper(TreeNode root) { |
|
|
|
|
if (root == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
helper(root.left); |
|
|
|
|
list.add(root.val); |
|
|
|
|
helper(root.right); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
class Solution { |
|
|
|
|
int result = 0, count = 1; |
|
|
|
|
|
|
|
|
|
public int kthLargest(TreeNode root, int k) { |
|
|
|
|
helper(root, k); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void helper(TreeNode root, int k) { |
|
|
|
|
if (root == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
helper(root.right, k); |
|
|
|
|
if (count++ == k) { |
|
|
|
|
result = root.val; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
helper(root.left, k); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |