Skip to content

Commit 78c46fb

Browse files
committed
solution 344 by java
1 parent f748e00 commit 78c46fb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/java/Solution344.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* LC#348: reverse string 反转字符串
3+
* Link:https://leetcode-cn.com/problems/reverse-string/
4+
* Solution:双指针,跟反转数组差不多。。。
5+
*/
6+
public class Solution344 {
7+
8+
public static void reverseString(char[] s) {
9+
int n = s.length, left = 0, right = n - 1;
10+
while (left < right) {
11+
char tmp = s[left];
12+
s[left] = s[right];
13+
s[right] = tmp;
14+
left++; right--;
15+
}
16+
}
17+
18+
public static void main(String[] args) {
19+
char[] s = {'h', 'e', 'l', 'l'};
20+
reverseString(s);
21+
for (char c : s) {
22+
System.out.println(c);
23+
}
24+
// System.out.println(Arrays.toString(s));
25+
}
26+
}

0 commit comments

Comments
 (0)