Skip to content

Commit 856ae79

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 424_Longest_Repeating_Character_Replacement.java
1 parent 40f861f commit 856ae79

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Sliding Window/424_Longest_Repeating_Character_Replacement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
class Solution {
22
public int characterReplacement(String s, int k) {
3-
int[] map = new int[26];
4-
int start = 0, maxCharCount = 0, result = 0;
3+
int[] hm = new int[26];
4+
int maxCharCount = 0, result = 0;
55

6-
for (int end = 0; end < s.length(); end++) {
7-
map[s.charAt(end) - 'A']++;
8-
maxCharCount = Math.max(maxCharCount, map[s.charAt(end) - 'A']);
6+
for (int start = 0, end = 0; end < s.length(); end++) {
7+
hm[s.charAt(end) - 'A']++;
8+
maxCharCount = Math.max(maxCharCount, hm[s.charAt(end) - 'A']);
99

10-
while (end - start + 1 - maxCharCount > k) {
11-
map[s.charAt(start) - 'A']--;
10+
if (end - start + 1 - maxCharCount > k) {
11+
hm[s.charAt(start) - 'A']--;
1212
++start;
1313
}
1414

0 commit comments

Comments
 (0)