Skip to content

Commit

Permalink
0257.二叉树的所有路径.md‘
Browse files Browse the repository at this point in the history
git commit -m 0257.二叉树的所有路径.’
  • Loading branch information
xllpiupiu committed May 26, 2021
1 parent 3fa5571 commit f51412e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions problems/0257.二叉树的所有路径.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,30 @@ class Solution:
```
Go:

JavaScript:
递归版本
```javascript
var binaryTreePaths = function(root) {
//递归遍历+递归三部曲
let res=[];
//1. 确定递归函数 函数参数
const getPath=function(node,curPath){
//2. 确定终止条件,到叶子节点就终止
if(node.left===null&&node.right===null){
curPath+=node.val;
res.push(curPath);
return ;
}
//3. 确定单层递归逻辑
curPath+=node.val+'->';
node.left&&getPath(node.left,curPath);
node.right&&getPath(node.right,curPath);
}
getPath(root,'');
return res;
};
```




Expand Down

0 comments on commit f51412e

Please sign in to comment.