Question: 744. Find Smallest Letter Greater Than Target
Intution:
Time Complexity:
Space Complexity:
Solution:
class Solution {
public char nextGreatestLetter(char[] letters, char target) {
int n = letters.length;
int low = 0;
int high = n - 1;
while (low < high) {
int mid = low + (high - low) / 2;
if (letters[mid] <= target) {
low = mid + 1;
} else {
high = mid;
}
}
return letters[low] > target ? letters[low] : letters[0];
}
}