@@ -0,0 +1,977 @@
+/***%0A * Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.%0A *%0A * For example:%0A * Given the below binary tree and sum = 22,%0A *               5%0A *              / %5C%0A *             4   8%0A *            /   / %5C%0A *           11  13  4%0A *          /  %5C      %5C%0A *         7    2      1%0A * return true, as there exist a root-to-leaf path 5-%3E4-%3E11-%3E2 which sum is 22.%0A */%0A/**%0A * Definition for binary tree%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    // Solution 1: O(n), O(log n)%0A    public boolean hasPathSum(TreeNode root, int sum) %7B%0A        if (root == null)   return false;%0A        if (root.left == null && root.right == null)%0A            return (sum == root.val);%0A        return hasPathSum(root.left, sum - root.val) %7C%7C hasPathSum(root.right, sum - root.val);%0A    %7D%0A%7D%0A

add PathSum.java