File tree 3 files changed +40
-0
lines changed
src/com/andavid/leetcode/_344
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 27
27
| 36 | [ Valid Sudoku] [ 036 ] |
28
28
| 48 | [ Rotate Image] [ 048 ] |
29
29
30
+ ** Strings**
31
+
32
+ | # | Title |
33
+ | :--: | :------------------------------------------ |
34
+ | 344 | [ Reverse String] [ 344 ] |
35
+
30
36
31
37
** 其他**
32
38
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments