File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/binary-tree-paths/
14
+
13
15
https://leetcode-cn.com/problems/trim-a-binary-search-tree/
14
16
15
17
https://leetcode.cn/problems/course-schedule/
Original file line number Diff line number Diff line change
1
+ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts" ;
2
+
3
+ export default function binaryTreePaths ( root : TreeNode | null ) : string [ ] {
4
+ const res : string [ ] = [ ] ;
5
+ if ( ! root ) {
6
+ return res ;
7
+ }
8
+ const path : number [ ] = [ ] ;
9
+ dfs ( root , res , path ) ;
10
+ return res ;
11
+ }
12
+ function dfs ( root : TreeNode , res : string [ ] , path : number [ ] ) {
13
+ path . push ( root . val ) ;
14
+ if ( ! root . left && ! root . right ) {
15
+ res . push ( path . join ( "->" ) ) ;
16
+ return ;
17
+ }
18
+
19
+ for ( const node of [ root . left , root . right ] . filter ( Boolean ) as TreeNode [ ] ) {
20
+ dfs ( node , res , path ) ;
21
+ path . pop ( ) ;
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments