@@ -0,0 +1,1841 @@
+package coding4fun;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Get the ancestors of a given node in a binary tree.%0A *%0A * %3Cpre%3E%0A *           1%0A *         /   %5C%0A *       2      3%0A *     /  %5C%0A *   4     5%0A *  /%0A * 7%0A *%0A * Input : 7%0A * Output: %5B4, 2, 1%5D%0A *%0A * Input : 5%0A * Output: %5B2, 1%5D%0A *%0A * Input : 3%0A * Output: %5B1%5D%0A *%0A * Input : 1%0A * Output: %5B%5D%0A * %3C/pre%3E%0A */%0Apublic class Problem57 %7B%0A    private static class TreeNode %7B%0A        private final int value;%0A        private TreeNode left;%0A        private TreeNode right;%0A%0A        public TreeNode(int value) %7B%0A            this.value = value;%0A        %7D%0A    %7D%0A%0A    private static List%3CInteger%3E getAncestors(TreeNode root, int value) %7B%0A        List%3CInteger%3E ancestors = new ArrayList%3C%3E();%0A        getAncestors(root, value, ancestors);%0A        return ancestors;%0A    %7D%0A%0A    private static boolean getAncestors(TreeNode root, int value, List%3CInteger%3E ancestors) %7B%0A        if (root == null) %7B%0A            return false;%0A        %7D%0A        if (root.value == value) %7B%0A            return true;%0A        %7D%0A        boolean a = getAncestors(root.left, value, ancestors);%0A        boolean b = getAncestors(root.right, value, ancestors);%0A        boolean c = a %7C%7C b;%0A        if (c) %7B%0A            ancestors.add(root.value);%0A        %7D%0A        return c;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        TreeNode root = new TreeNode(1);%0A        root.left = new TreeNode(2);%0A        root.left.left = new TreeNode(4);%0A        root.left.left.left = new TreeNode(7);%0A        root.left.right = new TreeNode(5);%0A        root.right = new TreeNode(3);%0A%0A        System.out.println(getAncestors(root, 7)); // %5B4, 2, 1%5D%0A        System.out.println(getAncestors(root, 5)); // %5B2, 1%5D%0A        System.out.println(getAncestors(root, 3)); // %5B1%5D%0A        System.out.println(getAncestors(root, 1)); // %5B%5D%0A    %7D%0A%7D%0A

Add problem 57