Skip to content

Commit c5407ce

Browse files
authored
Merge pull request gzc426#769 from MMzhe/patch-50
Create sourcema.md
2 parents 88650bf + f226234 commit c5407ce

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2019.01.14-leetcode257/sourcema.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# leetcode 257
2+
class Solution {
3+
public List<String> binaryTreePaths(TreeNode root) {
4+
List<String> list = new ArrayList<>();
5+
if (root == null) {
6+
return list;
7+
}
8+
dfs(root, list,new String());
9+
return list;
10+
}
11+
private void dfs(TreeNode root, List<String> list,String ret) {
12+
if (root.left==null&&root.right==null) {
13+
ret+=root.val;
14+
list.add(ret);
15+
return;
16+
}
17+
ret += root.val + "->";
18+
if(root.left!=null){
19+
dfs(root.left,list,ret);
20+
}
21+
if(root.right!=null){
22+
dfs(root.right,list,ret);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)