Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e4b42a

Browse files
feat: add typescript solution to lc problem: No.0917
No.0917.Reverse Only Letters
1 parent bb5a3f3 commit 9e4b42a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎solution/0900-0999/0917.Reverse Only Letters/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ class Solution {
114114
}
115115
```
116116

117+
### **TypeScript**
118+
119+
```ts
120+
function reverseOnlyLetters(s: string): string {
121+
const n = s.length;
122+
let i = 0, j = n - 1;
123+
let ans = [...s];
124+
while (i < j) {
125+
while (!/[a-zA-Z]/.test(ans[i]) && i < j) i++;
126+
while (!/[a-zA-Z]/.test(ans[j]) && i < j) j--;
127+
[ans[i], ans[j]] = [ans[j], ans[i]];
128+
i++;
129+
j--;
130+
}
131+
return ans.join('');
132+
};
133+
```
134+
117135
### **C++**
118136

119137
```cpp

‎solution/0900-0999/0917.Reverse Only Letters/README_EN.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ class Solution {
8282
}
8383
```
8484

85+
### **TypeScript**
86+
87+
```ts
88+
function reverseOnlyLetters(s: string): string {
89+
const n = s.length;
90+
let i = 0, j = n - 1;
91+
let ans = [...s];
92+
while (i < j) {
93+
while (!/[a-zA-Z]/.test(ans[i]) && i < j) i++;
94+
while (!/[a-zA-Z]/.test(ans[j]) && i < j) j--;
95+
[ans[i], ans[j]] = [ans[j], ans[i]];
96+
i++;
97+
j--;
98+
}
99+
return ans.join('');
100+
};
101+
```
102+
85103
### **C++**
86104

87105
```cpp
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function reverseOnlyLetters(s: string): string {
2+
const n = s.length;
3+
let i = 0, j = n - 1;
4+
let ans = [...s];
5+
while (i < j) {
6+
while (!/[a-zA-Z]/.test(ans[i]) && i < j) i++;
7+
while (!/[a-zA-Z]/.test(ans[j]) && i < j) j--;
8+
[ans[i], ans[j]] = [ans[j], ans[i]];
9+
i++;
10+
j--;
11+
}
12+
return ans.join('');
13+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /