Skip to content

Commit b4b86b1

Browse files
committed
fix: error rust code
No.0744.Find Smallest Letter Greater Than Target
1 parent 5612f16 commit b4b86b1

File tree

1 file changed

+13
-11
lines changed
  • solution/0700-0799/0744.Find Smallest Letter Greater Than Target

1 file changed

+13
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
function nextGreatestLetter(letters: string[], target: string): string {
2-
let left = 0,
3-
right = letters.length;
4-
let x = target.charCodeAt(0);
5-
while (left < right) {
6-
let mid = (left + right) >> 1;
7-
if (x < letters[mid].charCodeAt(0)) {
8-
right = mid;
9-
} else {
10-
left = mid + 1;
1+
impl Solution {
2+
pub fn next_greatest_letter(letters: Vec<char>, target: char) -> char {
3+
let n = letters.len();
4+
let mut l = 0;
5+
let mut r = n;
6+
while l < r {
7+
let mid = l + r >> 1;
8+
if letters[mid] <= target {
9+
l = mid + 1;
10+
} else {
11+
r = mid;
12+
}
1113
}
14+
letters[l % n]
1215
}
13-
return letters[left % letters.length];
1416
}

0 commit comments

Comments
 (0)