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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
0744. 寻找比目标字母大的最小字母
https://algo.itcharge.cn/solutions/0700-0799/find-smallest-letter-greater-than-target/
Beta Was this translation helpful? Give feedback.
All reactions