@@ -0,0 +1,1297 @@
+package com.github.cschen1205.jp.chap04;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport static jdk.nashorn.internal.objects.Global.print;%0A%0A/**%0A * Created by memeanalytics on 29/6/17.%0A * You are given a binary tree in which each node contains a value%0A * Design an algorithm to print all paths which sum up to that value%0A * Note that it can be any path in the tree - it does not have to start at the root%0A */%0Apublic class Q08 %7B%0A    public static class TreeNode %7B%0A        public TreeNode left;%0A        public TreeNode right;%0A        public int data;%0A    %7D%0A%0A    public static void findSum(TreeNode root, int sum, ArrayList%3CInteger%3E buffer, int level)%7B%0A        if(root == null) return;%0A        buffer.add(root.data);%0A        int temp = sum;%0A        for(int i = level; i %3E= 1; i--)%7B%0A            temp -= buffer.get(i);%0A            if(temp == 0) %7B%0A                print(buffer, i, level);%0A            %7D%0A        %7D%0A        findSum(root.left, sum, (ArrayList%3CInteger%3E) buffer.clone(), level+1);%0A        findSum(root.right, sum, (ArrayList%3CInteger%3E) buffer.clone(), level + 1);%0A    %7D%0A%0A    public static void print(List%3CInteger%3E buffer, int i, int level)%7B%0A        for(int j = level; j %3C= i; --j) %7B%0A            System.out.print(buffer.get(i) + %22 %22);%0A        %7D%0A        System.out.println();%0A    %7D%0A%7D%0A

find sum