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 0c4e001 commit 9c22f9eCopy full SHA for 9c22f9e
longest-repeating-character-replacement/hu6r1s.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def characterReplacement(self, s: str, k: int) -> int:
3
+ counts = {}
4
+ left = 0
5
+ max_count = 0
6
+ res = 0
7
+
8
+ for right in range(len(s)):
9
+ counts[s[right]] = counts.get(s[right], 0) + 1
10
+ max_count = max(max_count, counts[s[right]])
11
12
+ while (right - left + 1) - max_count > k:
13
+ counts[s[left]] -= 1
14
+ left += 1
15
16
+ res = max(res, right - left + 1)
17
18
+ return res
0 commit comments