Skip to content

Commit c196703

Browse files
committed
https://leetcode.cn/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
1 parent dcdd3f2 commit c196703

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
49+
4850
https://leetcode.cn/problems/numbers-at-most-n-given-digit-set/
4951

5052
https://leetcode.cn/problems/er-cha-shu-ran-se-UGC/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
2+
3+
function kthLargest(root: TreeNode | null, k: number): number {
4+
let i = 1;
5+
for (const v of reverseInOrderIterator(root)) {
6+
if (i === k) return v;
7+
i++;
8+
}
9+
throw Error("unreachable");
10+
}
11+
export function* reverseInOrderIterator(
12+
root: TreeNode | null,
13+
): Generator<number> {
14+
if (!root) {
15+
return;
16+
}
17+
yield* reverseInOrderIterator(root.right);
18+
yield root.val;
19+
yield* reverseInOrderIterator(root.left);
20+
}
21+
export default kthLargest;

mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { parseComplex } from "./complex-number-multiplication/parse_complex.ts";
99
import { buildBST } from "./convert-sorted-list-to-binary-search-tree/buildBST.ts";
1010
import { PrefixTreeInsert } from "./design-add-and-search-words-data-structure/PrefixTreeInsert.ts";
1111
import { DoublyLinkedList } from "./design-linked-list/DoublyLinkedList.ts";
12+
import { reverseInOrderIterator } from "./er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.ts";
1213
import { ArrayToCircularDoublyTreeList } from "./er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/ArrayToCircularDoublyTreeList.ts";
1314
import { NestedIntegerFrom } from "./flatten-nested-list-iterator/NestedIntegerFrom.ts";
1415
import { deduplication } from "./fraction-addition-and-subtraction/deduplication.ts";
@@ -155,6 +156,7 @@ export {
155156
ArrayToCircularDoublyTreeList,
156157
getVariable,
157158
InOrderIterator,
159+
reverseInOrderIterator,
158160
ScopeList,
159161
traverseInOrder,
160162
UnionFind,

0 commit comments

Comments
 (0)