public boolean hasPathSumRec(TreeNode root, int sum) {
        if(root == null) return false;
        if(root.left == null && root.right == null) return sum == root.val;
        return hasPathSumRec(root.left, sum - root.val) || hasPathSumRec(root.right, sum - root.val);
    }