class Solution {
public:
char nextGreatestLetter(vector<char>& letters, char target) {
int l = -1, r = letters.size();
while (l + 1 < r) {
int mid = l + r >> 1;
if (letters[mid] > target) r = mid;
else l = mid;
}
if (r == letters.size()) return letters[0];
else return letters[r];
}
};