Skip to content

Commit a92e9d1

Browse files
refactor 344
1 parent 838be6b commit a92e9d1

File tree

1 file changed

+13
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@
66
* Write a function that takes a string as input and returns the string reversed.
77
88
Example:
9-
Given s = "hello", return "olleh".*/
9+
Given s = "hello", return "olleh".
10+
*/
1011
public class _344 {
11-
public String reverseString_cheating(String s) {
12-
return new StringBuilder(s).reverse().toString();
13-
}
14-
15-
public String reverseString(String s) {
16-
int i = 0;
17-
int j = s.length() - 1;
18-
char[] chars = s.toCharArray();
19-
while (i < j) {
20-
char temp = chars[i];
21-
chars[i++] = chars[j];
22-
chars[j--] = temp;
23-
12+
public static class Solution1 {
13+
public String reverseString(String s) {
14+
int i = 0;
15+
int j = s.length() - 1;
16+
char[] chars = s.toCharArray();
17+
while (i < j) {
18+
char temp = chars[i];
19+
chars[i++] = chars[j];
20+
chars[j--] = temp;
21+
}
22+
return new String(chars);
2423
}
25-
return new String(chars);
2624
}
2725
}

0 commit comments

Comments
 (0)