@@ -0,0 +1,1568 @@
+/**%0A * Definition for a binary tree node.%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public List%3CString%3E binaryTreePaths(TreeNode root) %7B%0A        if(root == null)%7B%0A            return Collections.emptyList();%0A        %7Delse if(root.left == null && root.right == null)%7B%0A            List%3CString%3E result = new ArrayList%3CString%3E();%0A            result.add(%22%22+root.val);%0A            return result;%0A        %7Delse if(root.left != null && root.right == null)%7B%0A            return addRoot1(root.val, binaryTreePaths(root.left));%0A        %7Delse if(root.left == null && root.right != null)%7B%0A            return addRoot1(root.val, binaryTreePaths(root.right));%0A        %7Delse%7B%0A            return addRoot2(root.val, binaryTreePaths(root.left), binaryTreePaths(root.right));%0A        %7D%0A    %7D%0A    %0A    private List%3CString%3E addRoot1(int val, List%3CString%3E childPaths)%7B%0A        int size = childPaths.size();%0A        for(int i = 0; i %3C size; i ++)%7B%0A            childPaths.set(i, val + %22-%3E%22 + childPaths.get(i));%0A        %7D%0A        return childPaths;%0A    %7D%0A    %0A    private List%3CString%3E addRoot2(int val, List%3CString%3E leftPaths, List%3CString%3E rightPaths)%7B%0A        int size = leftPaths.size();%0A        for(int i = 0; i %3C size; i ++)%7B%0A            leftPaths.set(i, val + %22-%3E%22 + leftPaths.get(i));%0A        %7D%0A        size = rightPaths.size();%0A        for(int i = 0; i %3C size; i ++)%7B%0A            leftPaths.add(val + %22-%3E%22 + rightPaths.get(i));%0A        %7D%0A        return leftPaths;%0A    %7D%0A%7D

Q257 Binary Tree Paths