Given a binary tree and an integer S, check whether there is root to leaf path wiht its sum as S.
S = 2Output: 0Explanation:
There is no root to leaf path with sum 2.
S = 4Output: 1Explanation:
The sum of path from leaf node 3 to root 1 is 4.
You dont need to read input or print anything. Complete the function hasPathSum() which takes root node and target sum S as input parameter and returns true if path exists otherwise it returns false.
Expected Time Complexity: O(N) Expected Auxiliary Space: O(height of tree)