public boolean hasPathSum(TreeNode root, int sum) {
        boolean result = false;

        if (root != null) {
            int currentSum = root.getVal();

            if (root.getLeft() == null && root.getRight() == null) {
                return currentSum == sum;
            }

            sum -= currentSum;

            if (root.getLeft() != null) {
                result = hasPathSum(root.getLeft(), sum);
            }

            if (!result && root.getRight() != null) {
                result = hasPathSum(root.getRight(), sum);
            }
        }
        return result;
    }