257. 二叉树的所有路径
class Solution {
public List<String> binaryTreePaths(TreeNode root) {
List<String> res=new ArrayList<>();
if (root==null) return res;
helper(root,"",res);
return res;
}
public void helper (TreeNode root,String temp,List<String> res){
if (root==null) return;
if (root.left==null && root.right==null){
res.add(temp+root.val);
return;//终止条件。。返回结果
}
if (root.left!=null){//去递归
helper(root.left,temp+root.val+"->",res);
}
if (root.right!=null){//去递归
helper(root.right,temp+root.val+"->",res);
}
}
}