Skip to content

Commit 7d0f4da

Browse files
committed
add 344
1 parent df22052 commit 7d0f4da

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
| 36 | [Valid Sudoku][036] |
2828
| 48 | [Rotate Image][048] |
2929

30+
**Strings**
31+
32+
| # | Title |
33+
| :--: | :------------------------------------------ |
34+
| 344 | [Reverse String][344] |
35+
3036

3137
**其他**
3238

note/344/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# [Reverse String][title]
2+
3+
## Description
4+
5+
Write a function that takes a string as input and returns the string reversed.
6+
7+
**Example:**
8+
Given s = "hello", return "olleh".
9+
10+
## 思路
11+
使用 StringBuilder 的 reverse 方法。
12+
13+
## [完整代码][src]
14+
15+
```java
16+
class Solution {
17+
public String reverseString(String s) {
18+
return new StringBuilder(s).reverse().toString();
19+
}
20+
}
21+
```
22+
23+
[title]: https://leetcode.com/problems/reverse-string
24+
[src]: https://github.com/andavid/leetcode-java/blob/master/src/com/andavid/leetcode/_344/Solution.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public String reverseString(String s) {
3+
return new StringBuilder(s).reverse().toString();
4+
}
5+
6+
public static void main(String[] args) {
7+
Solution solution = new Solution();
8+
System.out.println(solution.reverseString("hello"));
9+
}
10+
}

0 commit comments

Comments
 (0)