File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 26
26
| 110| [ 平衡二叉树] ( https://leetcode.cn/problems/balanced-binary-tree/ ) | [ JavaScript] ( ./algorithms/balanced-binary-tree.js ) | Easy|
27
27
| 111| [ 二叉树的最小深度] ( https://leetcode.cn/problems/minimum-depth-of-binary-tree/ ) | [ JavaScript] ( ./algorithms/minimum-depth-of-binary-tree.js ) | Easy|
28
28
| 112| [ 路径总和] ( https://leetcode.cn/problems/path-sum/ ) | [ JavaScript] ( ./algorithms/path-sum.js ) | Easy|
29
- | 113| [ 路径总和 II] ( https://leetcode.cn/problems/path-sum-ii/ ) | [ JavaScript] ( ) | Medium|
29
+ | 113| [ 路径总和 II] ( https://leetcode.cn/problems/path-sum-ii/ ) | [ JavaScript] ( ./algorithms/path-sum-ii.js ) | Medium|
30
30
| 136| [ 只出现一次的数字] ( https://leetcode-cn.com/problems/single-number/ ) | [ JavaScript] ( ./algorithms/single-number.js ) | Easy|
31
31
| 141| [ 环形链表] ( https://leetcode-cn.com/problems/linked-list-cycle/ ) | [ JavaScript] ( ./algorithms/linked-list-cycle.js ) | Easy|
32
32
| 142| [ 环形链表 II] ( https://leetcode.cn/problems/linked-list-cycle-ii/ ) | [ JavaScript] ( ./algorithms/linked-list-cycle-ii.js ) | Medium|
41
41
| 231| [ 2 的幂] ( https://leetcode.cn/problems/power-of-two/ ) | [ JavaScript] ( ./algorithms/power-of-two.js ) | Easy|
42
42
| 234| [ 回文链表] ( https://leetcode-cn.com/problems/palindrome-linked-list/ ) | [ JavaScript] ( ./algorithms/palindrome-linked-list.js ) | Easy|
43
43
| 237| [ 删除链表中的节点] ( https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ ) | [ JavaScript] ( ./algorithms/delete-node-in-a-linked-list.js ) | Easy|
44
+ | 257| [ 二叉树的所有路径] ( https://leetcode.cn/problems/binary-tree-paths/ ) | [ JavaScript] ( ./algorithms/binary-tree-paths.js ) | Easy|
44
45
| 328| [ 奇偶链表] ( https://leetcode.cn/problems/odd-even-linked-list/ ) | [ JavaScript] ( ./algorithms/odd-even-linked-list.js ) | Medium|
45
46
| 344| [ 反转字符串] ( https://leetcode-cn.com/problems/reverse-string/ ) | [ JavaScript] ( ./algorithms/reverse-string.js ) | Easy|
46
47
| 349| [ 两个数组的交集] ( https://leetcode-cn.com/problems/intersection-of-two-arrays/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-arrays.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
+ /**
10
+ * 二叉树的所有路径
11
+ * @param {TreeNode } root
12
+ * @return {string[] }
13
+ */
14
+ var binaryTreePaths = function ( root ) {
15
+ const paths = [ ] ;
16
+ const dfs = ( node , path = "" ) => {
17
+ if ( node ) {
18
+ path += node . val ;
19
+ // leaf node
20
+ if ( ! node . left && ! node . right ) {
21
+ paths . push ( path ) ;
22
+ } else {
23
+ path += "->" ;
24
+ dfs ( node . left , path ) ;
25
+ dfs ( node . right , path ) ;
26
+ }
27
+ }
28
+ } ;
29
+ dfs ( root ) ;
30
+ return paths ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments