Why would BFS solution not work, i.e iterating through BFS and then finding the possibile paths from each node.

class Solution {

static int counter=0;

public int pathSum(TreeNode root, int sum) {

Queue<TreeNode> q = new LinkedList<TreeNode>();

if (root==null) return 0;

q.add(root);

while (!q.isEmpty()){

TreeNode curr = q.remove();

int x=sup(curr, sum);

System.out.println(x);

counter+=x;

if (curr.left != null) q.add(curr.left);

if (curr.right != null) q.add(curr.right);

}

return counter;

}

public int sup(TreeNode curr, int sum){
int f=0;
if (curr.val==sum) f++;
if (curr.left== null && curr.right==null && curr.val!=sum) return 0;
int left=0;
int right=0;
if (curr.left != null) {
left = sup(curr.left, sum-curr.val);
}
if (curr.right != null) {
right = sup(curr.right, sum-curr.val);
}
return f+left+right;
}

}