Skip to content

Commit 5e27b1a

Browse files
refactor 344
1 parent 45b4b5b commit 5e27b1a

File tree

1 file changed

+5
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+5
-9
lines changed

src/main/java/com/fishercoder/solutions/_344.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
public class _344 {
44
public static class Solution1 {
5-
public String reverseString(String s) {
6-
int i = 0;
7-
int j = s.length() - 1;
8-
char[] chars = s.toCharArray();
9-
while (i < j) {
10-
char temp = chars[i];
11-
chars[i++] = chars[j];
12-
chars[j--] = temp;
5+
public void reverseString(char[] s) {
6+
for (int left = 0, right = s.length - 1; left < right; left++, right--) {
7+
char tmp = s[left];
8+
s[left] = s[right];
9+
s[right] = tmp;
1310
}
14-
return new String(chars);
1511
}
1612
}
1713
}

0 commit comments

Comments
 (0)