We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f748e00 commit 78c46fbCopy full SHA for 78c46fb
src/main/java/Solution344.java
@@ -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