Skip to content

Commit 9c22f9e

Browse files
committed
feat: longest-repeating-character-replacement problem
1 parent 0c4e001 commit 9c22f9e

File tree

1 file changed

+18
-0
lines changed
  • longest-repeating-character-replacement

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)