class Solution{ public: int searchBST(Node* root, int target, int ans = -1){ if(!root){ return ans; } if(root->data <= target){ ans = root->data; return searchBST(root->right,target, ans); } return searchBST(root->left, target, ans); } int floor(Node* root, int x) { // Code here if(!root ) return -1; return searchBST(root, x); } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter