2023-06-09 16:04:35 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Solution {
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
|
|
|
char nextGreatestLetter(const std::vector<char> &letters, char target) {
|
2023-06-09 16:04:35 +02:00
|
|
|
auto it = std::lower_bound(letters.begin(), letters.end(), target + 1);
|
|
|
|
return it == letters.end() ? letters.front() : *it;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
int main() {
|
2023-06-09 16:04:35 +02:00
|
|
|
Solution s;
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
assert((s.nextGreatestLetter(std::vector{'c', 'f', 'j'}, 'a') == 'c'));
|
|
|
|
assert((s.nextGreatestLetter(std::vector{'c', 'f', 'j'}, 'c') == 'f'));
|
|
|
|
assert((s.nextGreatestLetter(std::vector{'x', 'x', 'y', 'y'}, 'z') == 'x'));
|
2023-06-09 16:04:35 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|