0744. 寻找比目标字母大的最小字母 #173
Replies: 1 comment
-
c++ class Solution {
public:
char nextGreatestLetter(vector<char>& letters, char target) {
int n = letters.size();
char ch = letters[n - 1];
if (ch <= target) return letters[0];
int left = 0, right = n - 1;
while (left <= right) {
int mid = left + ((right - left) / 2);
if (letters[mid] <= target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return letters[left];
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0744. 寻找比目标字母大的最小字母
https://algo.itcharge.cn/Solutions/0700-0799/find-smallest-letter-greater-than-target/
Beta Was this translation helpful? Give feedback.
All reactions