I am getting error, not all code path returns a value, please could anyone help me through this. whats causing it and how to avoid this error.
i knw its eay one but I am stuck. Please suggest. :)
here is my code :
{
private TreeNode dfs(TreeNode root, int val)
{
if (root == null)
{
return null;
}
if (root.val == val)
{
return root;
}
if(val < root.val) // if root is big go left
{
return dfs(root.left, val);
}
return dfs(root.right, val); // otherwise go right
}
public TreeNode SearchBST(TreeNode root, int val)
{
dfs(root, val);
}
}```