leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0744.cpp (542B)
0 class Solution {
1 public:
2 char nextGreatestLetter(vector<char> &letters, char target) {
3 if (target >= letters.back()) return letters.front();
4 int low = 0, high = letters.size() - 1;
5 target++;
6 while (low < high) {
7 int mid = low + (high - low) / 2;
8 if (letters[mid] == target)
9 return letters[mid];
10 else if (letters[mid] < target)
11 low = mid + 1;
12 else
13 high = mid;
14 }
15 return letters[high];
16 }
17 };