File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed
src/main/java/com/leetcode/strings Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change 22
33/**
44 * Problem: https://leetcode.com/problems/reverse-string-ii/
5- *
5+ *
66 * @author rampatra
77 * @since 2019-04-20
88 */
@@ -13,7 +13,7 @@ public class ReverseStringII {
1313 * where,
1414 * n = no. of characters in string
1515 * <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>.
1717 *
1818 * @param str
1919 * @param k
@@ -22,14 +22,8 @@ public class ReverseStringII {
2222 public static String reverseStr (String str , int k ) {
2323 char [] chars = str .toCharArray ();
2424 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 ));
3327 }
3428 return new String (chars );
3529 }
You can’t perform that action at this time.
0 commit comments