mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -142,7 +142,7 @@ class Solution {
|
|||||||
|
|
||||||
Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
|
Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
|
||||||
// 根据map的value值正序排,相当于一个小顶堆
|
// 根据map的value值正序排,相当于一个小顶堆
|
||||||
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o2.getValue() - o1.getValue());
|
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o1.getValue() - o2.getValue());
|
||||||
for (Map.Entry<Integer, Integer> entry : entries) {
|
for (Map.Entry<Integer, Integer> entry : entries) {
|
||||||
queue.offer(entry);
|
queue.offer(entry);
|
||||||
if (queue.size() > k) {
|
if (queue.size() > k) {
|
||||||
|
@ -116,19 +116,19 @@ Java:
|
|||||||
```Java
|
```Java
|
||||||
// 前序遍历·递归·LC144_二叉树的前序遍历
|
// 前序遍历·递归·LC144_二叉树的前序遍历
|
||||||
class Solution {
|
class Solution {
|
||||||
ArrayList<Integer> preOrderReverse(TreeNode root) {
|
public List<Integer> preorderTraversal(TreeNode root) {
|
||||||
ArrayList<Integer> result = new ArrayList<Integer>();
|
List<Integer> result = new ArrayList<Integer>();
|
||||||
preOrder(root, result);
|
preorder(root, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void preOrder(TreeNode root, ArrayList<Integer> result) {
|
public void preorder(TreeNode root, List<Integer> result) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result.add(root.val); // 注意这一句
|
result.add(root.val);
|
||||||
preOrder(root.left, result);
|
preorder(root.left, result);
|
||||||
preOrder(root.right, result);
|
preorder(root.right, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 中序遍历·递归·LC94_二叉树的中序遍历
|
// 中序遍历·递归·LC94_二叉树的中序遍历
|
||||||
|
Reference in New Issue
Block a user