We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3fa5571 commit f51412eCopy full SHA for f51412e
problems/0257.二叉树的所有路径.md
@@ -351,6 +351,30 @@ class Solution:
351
```
352
Go:
353
354
+JavaScript:
355
+递归版本
356
+```javascript
357
+var binaryTreePaths = function(root) {
358
+ //递归遍历+递归三部曲
359
+ let res=[];
360
+ //1. 确定递归函数 函数参数
361
+ const getPath=function(node,curPath){
362
+ //2. 确定终止条件,到叶子节点就终止
363
+ if(node.left===null&&node.right===null){
364
+ curPath+=node.val;
365
+ res.push(curPath);
366
+ return ;
367
+ }
368
+ //3. 确定单层递归逻辑
369
+ curPath+=node.val+'->';
370
+ node.left&&getPath(node.left,curPath);
371
+ node.right&&getPath(node.right,curPath);
372
373
+ getPath(root,'');
374
+ return res;
375
+};
376
+```
377
+
378
379
380
0 commit comments