public boolean hasPathSum(TreeNode root, int sum) {
        boolean result1 = false;
        boolean result2 = false;
        if (root == null) {
            return false;
        }
        if (root.val == sum && root.left == null && root.right == null) {
            return true;
        }

        if (root.left != null) {
            result1 = hasPathSum(root.left, sum - root.val);
        }
        if (root.right != null) {
            result2 = hasPathSum(root.right, sum - root.val);
        }
        return result1 || result2;
    }