1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/cpp/find-smallest-letter-greater-than-target.cpp
Matej Focko b229608723
cpp(chore): add clang-format style and format
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 12:06:54 +01:00

21 lines
593 B
C++

#include <algorithm>
#include <cassert>
#include <vector>
class Solution {
public:
char nextGreatestLetter(const std::vector<char> &letters, char target) {
auto it = std::lower_bound(letters.begin(), letters.end(), target + 1);
return it == letters.end() ? letters.front() : *it;
}
};
int main() {
Solution s;
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'));
return 0;
}