class Solution {
public:
char bsf(vector<char> letters, char target)
{
char ans=letters[0];
int n=letters.size();
int l=0,h=n-1;
int mid=l+(h-l)/2;
while(l<=h)
{
if(letters[mid]-'a'>target-'a')
{
ans=letters[mid];
h=mid-1;
}
else l=mid+1;
mid=l+(h-l)/2;
}
return ans;
}
char nextGreatestLetter(vector<char>& letters, char target) {
char result=bsf(letters, target);
return result;
}
};
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