Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
339 B
0
Indexable
Never
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;
    }
}