Skip to content

Commit 4cb071a

Browse files
authored
feat: add typescript solution to lc problem: No.0744.Find Smallest Letter Greater Than Target (doocs#459)
1 parent 7fb80c1 commit 4cb071a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ class Solution {
103103
}
104104
```
105105

106+
### **TypeScript**
107+
108+
```ts
109+
function nextGreatestLetter(letters: string[], target: string): string {
110+
let left = 0, right = letters.length;
111+
let x = target.charCodeAt(0);
112+
while (left < right) {
113+
let mid = (left + right) >> 1;
114+
if (x < letters[mid].charCodeAt(0)) {
115+
right = mid;
116+
} else {
117+
left = mid + 1;
118+
}
119+
}
120+
return letters[left % letters.length];
121+
};
122+
```
123+
106124
### **C++**
107125

108126
```cpp

solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ class Solution {
132132
}
133133
```
134134

135+
### **TypeScript**
136+
137+
```ts
138+
function nextGreatestLetter(letters: string[], target: string): string {
139+
let left = 0, right = letters.length;
140+
let x = target.charCodeAt(0);
141+
while (left < right) {
142+
let mid = (left + right) >> 1;
143+
if (x < letters[mid].charCodeAt(0)) {
144+
right = mid;
145+
} else {
146+
left = mid + 1;
147+
}
148+
}
149+
return letters[left % letters.length];
150+
};
151+
```
152+
135153
### **C++**
136154

137155
```cpp
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function nextGreatestLetter(letters: string[], target: string): string {
2+
let left = 0, right = letters.length;
3+
let x = target.charCodeAt(0);
4+
while (left < right) {
5+
let mid = (left + right) >> 1;
6+
if (x < letters[mid].charCodeAt(0)) {
7+
right = mid;
8+
} else {
9+
left = mid + 1;
10+
}
11+
}
12+
return letters[left % letters.length];
13+
};

0 commit comments

Comments
 (0)