Untitled

 avatar
unknown
c_cpp
2 years ago
339 B
1
Indexable
int floorInBST(TreeNode<int> * root, int X)
{
    if (root == NULL)
        return -1;

    if (root -> val == X)
        return root -> val;
    else if (X < root -> val)
        return floorInBST(root -> left, X);
    else {
        int val;
        return (val = floorInBST(root->right, X)) != -1 ? val : root->val;
    }
}