MyJavaEasySolution


  • 5
    D
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> res = new ArrayList<String>();
        if(root != null){
            res.addAll(binaryTreePaths(root.left));
            res.addAll(binaryTreePaths(root.right));
            for(int i=0; i < res.size();i++){
                String path = root.val+"->"+res.get(i);
                res.set(i,path);
            }
            
            if(res.size()==0) res.add(String.valueOf(root.val));
        }
        return res;
         
    }

  • 0
    M
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.