File tree Expand file tree Collapse file tree 1 file changed +13
-15
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Original file line number Diff line number Diff line change 6
6
* Write a function that takes a string as input and returns the string reversed.
7
7
8
8
Example:
9
- Given s = "hello", return "olleh".*/
9
+ Given s = "hello", return "olleh".
10
+ */
10
11
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 );
24
23
}
25
- return new String (chars );
26
24
}
27
25
}
You can’t perform that action at this time.
0 commit comments