We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 933bc38 commit fd79157Copy full SHA for fd79157
src/main/java/com/leetcode/strings/ReverseStringII.java
@@ -2,7 +2,7 @@
2
3
/**
4
* Problem: https://leetcode.com/problems/reverse-string-ii/
5
- *
+ *
6
* @author rampatra
7
* @since 2019年04月20日
8
*/
@@ -13,7 +13,7 @@ public class ReverseStringII {
13
* where,
14
* n = no. of characters in string
15
* <p>
16
- * Runtime: <a href="https://leetcode.com/submissions/detail/223714484/">0 ms</a>.
+ * Runtime: <a href="https://leetcode.com/submissions/detail/223715011/">0 ms</a>.
17
*
18
* @param str
19
* @param k
@@ -22,14 +22,8 @@ public class ReverseStringII {
22
public static String reverseStr(String str, int k) {
23
char[] chars = str.toCharArray();
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;
+ for (int i = 0; i < len; i += 2 * k) {
+ reverse(chars, i, Math.min(len, i + k));
33
}
34
return new String(chars);
35
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments