跳转至

寻找比目标字母大的最小字母⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

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];
    }
};