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 ed629cd commit 9b99564Copy full SHA for 9b99564
longest-repeating-character-replacement/eunhwa99.java
@@ -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