Skip to content

Commit 9b99564

Browse files
author
eunhwa99
committed
palindromic substrings
1 parent ed629cd commit 9b99564

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution{
2+
public int characterReplacement(String s, int k) {
3+
int[] count = new int[26];
4+
int maxCount = 0;
5+
int left = 0;
6+
int result = 0;
7+
8+
for (int right = 0; right < s.length(); right++) {
9+
char currentChar = s.charAt(right);
10+
count[currentChar - 'A']++;
11+
maxCount = Math.max(maxCount, count[currentChar - 'A']);
12+
13+
while (right - left + 1 - maxCount > k) {
14+
count[s.charAt(left) - 'A']--;
15+
left++;
16+
}
17+
18+
result = Math.max(result, right - left + 1);
19+
}
20+
21+
22+
return result;
23+
}
24+
}

0 commit comments

Comments
 (0)