File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
49
+
48
50
https://leetcode.cn/problems/numbers-at-most-n-given-digit-set/
49
51
50
52
https://leetcode.cn/problems/er-cha-shu-ran-se-UGC/
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { parseComplex } from "./complex-number-multiplication/parse_complex.ts";
9
9
import { buildBST } from "./convert-sorted-list-to-binary-search-tree/buildBST.ts" ;
10
10
import { PrefixTreeInsert } from "./design-add-and-search-words-data-structure/PrefixTreeInsert.ts" ;
11
11
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" ;
12
13
import { ArrayToCircularDoublyTreeList } from "./er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/ArrayToCircularDoublyTreeList.ts" ;
13
14
import { NestedIntegerFrom } from "./flatten-nested-list-iterator/NestedIntegerFrom.ts" ;
14
15
import { deduplication } from "./fraction-addition-and-subtraction/deduplication.ts" ;
@@ -155,6 +156,7 @@ export {
155
156
ArrayToCircularDoublyTreeList ,
156
157
getVariable ,
157
158
InOrderIterator ,
159
+ reverseInOrderIterator ,
158
160
ScopeList ,
159
161
traverseInOrder ,
160
162
UnionFind ,
You can’t perform that action at this time.
0 commit comments