Skip to content

Commit 9823aa7

Browse files
zhouboyi1998zhouboyi
authored andcommitted
docs(note): 添加题解:344. 反转字符串
1 parent 8aa6c3f commit 9823aa7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<h1 style="text-align: center;"> <span style="color: #00AF9B;">344. 反转字符串</span> </h1>
2+
3+
### 🚀 LeetCode
4+
5+
<base target="_blank">
6+
7+
<span style="color: #00AF9B;">**Easy**</span> [**https://leetcode.cn/problems/reverse-string/**](https://leetcode.cn/problems/reverse-string/)
8+
9+
---
10+
11+
### ❓ Description
12+
13+
<br/>
14+
15+
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 `s` 的形式给出。
16+
17+
不要给另外的数组分配额外的空间,你必须 [**原地**](https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95) **修改输入数组**、使用 `O(1)` 的额外空间解决这一问题。
18+
19+
<br/>
20+
21+
**示例 1:**
22+
23+
```
24+
输入: s = ["h", "e", "l", "l", "o"]
25+
输出: ["o", "l", "l", "e", "h"]
26+
```
27+
28+
**示例 2:**
29+
30+
```
31+
输入: s = ["H", "a", "n", "n", "a", "h"]
32+
输出: ["h", "a", "n", "n", "a", "H"]
33+
```
34+
35+
<br/>
36+
37+
**提示:**
38+
39+
* `1 <= s.length <= 10^5`
40+
* `s[i]` 都是 `ASCII` 码表中的可打印字符
41+
42+
---
43+
44+
### ❗ Solution
45+
46+
<br/>
47+
48+
#### Java
49+
50+
```
51+
class Solution {
52+
public void reverseString(char[] s) {
53+
for (int left = 0, right = s.length - 1; left < right; left++, right--) {
54+
char temp = s[left];
55+
s[left] = s[right];
56+
s[right] = temp;
57+
}
58+
}
59+
}
60+
```

markdown/hello/0000.Hello.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
| <span style="color: #FFB822;">**Medium**</span> | [**0289.生命游戏**](../medium/0289.生命游戏.md) |
7777
| <span style="color: #00AF9B;">**Easy**</span> | [**0292.Nim游戏**](../easy/0292.Nim游戏.md) |
7878
| <span style="color: #00AF9B;">**Easy**</span> | [**0326.3的幂**](../easy/0326.3的幂.md) |
79+
| <span style="color: #00AF9B;">**Easy**</span> | [**0344.反转字符串**](../easy/0344.反转字符串.md) |
7980
| <span style="color: #00AF9B;">**Easy**</span> | [**0374.猜数字大小**](../easy/0374.猜数字大小.md) |
8081
| <span style="color: #FFB822;">**Medium**</span> | [**0397.整数替换**](../medium/0397.整数替换.md) |
8182
| <span style="color: #FFB822;">**Medium**</span> | [**0413.等差数列划分**](../medium/0413.等差数列划分.md) |

0 commit comments

Comments
 (0)