Skip to content

Commit d80cd51

Browse files
committed
Refactored Consecutive Characters.java
1 parent 5721daf commit d80cd51

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Easy/Consecutive Characters.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
class Solution {
22
public int maxPower(String s) {
3-
int count = 0;
4-
int idx = 0;
5-
int n = s.length();
6-
while (idx < n) {
7-
char c = s.charAt(idx);
8-
int tempCount = 0;
9-
while (idx < n && s.charAt(idx) == c) {
3+
int maximumRepeatingCount = 0;
4+
for (int idx = 0; idx < s.length();) {
5+
char currentChar = s.charAt(idx);
6+
int currIdx = idx;
7+
while (idx < s.length() && s.charAt(idx) == currentChar) {
108
idx++;
11-
tempCount++;
129
}
13-
count = Math.max(count, tempCount);
10+
maximumRepeatingCount = Math.max(maximumRepeatingCount, idx - currIdx);
1411
}
15-
return count;
12+
return maximumRepeatingCount;
1613
}
1714
}

0 commit comments

Comments
 (0)