Skip to content

Commit 92c9e06

Browse files
authored
feat: update solutions to lc problems: No.344,345 (#2987)
* No.0344.Reverse String * No.0345.Reverse Vowels of a String
1 parent 4f82fc8 commit 92c9e06

File tree

5 files changed

+12
-69
lines changed

5 files changed

+12
-69
lines changed

solution/0300-0399/0344.Reverse String/README.md

-29
Original file line numberDiff line numberDiff line change
@@ -154,33 +154,4 @@ var reverseString = function (s) {
154154

155155
<!-- solution:end -->
156156

157-
<!-- solution:start -->
158-
159-
### 方法二
160-
161-
<!-- tabs:start -->
162-
163-
#### Python3
164-
165-
```python
166-
class Solution:
167-
def reverseString(self, s: List[str]) -> None:
168-
s[:] = s[::-1]
169-
```
170-
171-
#### TypeScript
172-
173-
```ts
174-
/**
175-
Do not return anything, modify s in-place instead.
176-
*/
177-
function reverseString(s: string[]): void {
178-
s.reverse();
179-
}
180-
```
181-
182-
<!-- tabs:end -->
183-
184-
<!-- solution:end -->
185-
186157
<!-- problem:end -->

solution/0300-0399/0344.Reverse String/README_EN.md

+5-30
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ tags:
4343

4444
<!-- solution:start -->
4545

46-
### Solution 1
46+
### Solution 1: Two Pointers
47+
48+
We use two pointers $i$ and $j$, initially pointing to the start and end of the array respectively. Each time, we swap the elements at $i$ and $j$, then move $i$ forward and $j$ backward, until $i$ and $j$ meet.
49+
50+
The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)$.
4751

4852
<!-- tabs:start -->
4953

@@ -142,33 +146,4 @@ var reverseString = function (s) {
142146

143147
<!-- solution:end -->
144148

145-
<!-- solution:start -->
146-
147-
### Solution 2
148-
149-
<!-- tabs:start -->
150-
151-
#### Python3
152-
153-
```python
154-
class Solution:
155-
def reverseString(self, s: List[str]) -> None:
156-
s[:] = s[::-1]
157-
```
158-
159-
#### TypeScript
160-
161-
```ts
162-
/**
163-
Do not return anything, modify s in-place instead.
164-
*/
165-
function reverseString(s: string[]): void {
166-
s.reverse();
167-
}
168-
```
169-
170-
<!-- tabs:end -->
171-
172-
<!-- solution:end -->
173-
174149
<!-- problem:end -->

solution/0300-0399/0344.Reverse String/Solution2.py

-3
This file was deleted.

solution/0300-0399/0344.Reverse String/Solution2.ts

-6
This file was deleted.

solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ tags:
4343

4444
<!-- solution:start -->
4545

46-
### Solution 1
46+
### Solution 1: Two Pointers
47+
48+
We can use two pointers $i$ and $j$, initially pointing to the start and end of the string respectively.
49+
50+
In each loop, we check whether the character at $i$ is a vowel. If it's not, we move $i$ forward. Similarly, we check whether the character at $j$ is a vowel. If it's not, we move $j$ backward. If $i < j$ at this point, then both characters at $i$ and $j$ are vowels, so we swap these two characters. Then, we move $i$ forward and $j$ backward. We continue the above operations until $i \ge j$.
51+
52+
The time complexity is $O(n)$, where $n$ is the length of the string. The space complexity is $O(|\Sigma|)$, where $\Sigma$ is the size of the character set.
4753

4854
<!-- tabs:start -->
4955

0 commit comments

Comments
 (0)