Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 78c46fb

Browse files
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‎

Lines changed: 26 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /