forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_744.java
28 lines (27 loc) · 865 Bytes
/
_744.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions;
public class _744 {
public static class Solution1 {
public char nextGreatestLetter(char[] letters, char target) {
if (letters[0] > target) {
return letters[0];
}
int left = 0;
int right = letters.length - 1;
while (left < right) {
int mid = left + (right - left) / 2;
if (letters[mid] > target) {
while (letters[mid] > target) {
mid--;
}
return letters[++mid];
} else {
left = mid + 1;
}
}
if (right < letters.length && letters[right] > target) {
return letters[right];
}
return letters[0];
}
}
}