File tree 1 file changed +4
-10
lines changed
src/main/java/com/leetcode/strings
1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
* Problem: https://leetcode.com/problems/reverse-string-ii/
5
- *
5
+ *
6
6
* @author rampatra
7
7
* @since 2019-04-20
8
8
*/
@@ -13,7 +13,7 @@ public class ReverseStringII {
13
13
* where,
14
14
* n = no. of characters in string
15
15
* <p>
16
- * Runtime: <a href="https://leetcode.com/submissions/detail/223714484 /">0 ms</a>.
16
+ * Runtime: <a href="https://leetcode.com/submissions/detail/223715011 /">0 ms</a>.
17
17
*
18
18
* @param str
19
19
* @param k
@@ -22,14 +22,8 @@ public class ReverseStringII {
22
22
public static String reverseStr (String str , int k ) {
23
23
char [] chars = str .toCharArray ();
24
24
int len = str .length ();
25
- int i = 0 ;
26
- while (i < len ) {
27
- if (len - i + 1 >= 2 * k ) {
28
- reverse (chars , i , i + k );
29
- } else {
30
- reverse (chars , i , Math .min (len , i + k ));
31
- }
32
- i += 2 * k ;
25
+ for (int i = 0 ; i < len ; i += 2 * k ) {
26
+ reverse (chars , i , Math .min (len , i + k ));
33
27
}
34
28
return new String (chars );
35
29
}
You can’t perform that action at this time.
0 commit comments