char nextGreatestLetter(vector<char>& letters, char target) {
if(letters.back() <= target || letters.front()> target) return letters.front();
int lo = 0, hi = letters.size() - 1, mi;
while(lo<hi) {
mi = (lo + hi) /2;
if(mi == lo) break;
if(target < letters[mi]) hi = mi;
else if(target >= letters[mi]) lo = mi;
}
return letters[hi];
}
No comments:
Post a Comment