classSolution { public: charnextGreatestLetter(vector<char>& letters, char target){ // if the letter is bigger than the biggest in our sorted input then // just pick the smallest one since letters "wrap around" if (letters.back() <= target) return letters[0];
int low = 0; int high = letters.size() - 1; char res;
while (low <= high) { int mid = low + (high - low)/2; if (letters[mid] <= target) { low = mid + 1; } else { res = letters[mid]; high = mid - 1; } }