Skip to content

Commit a073aef

Browse files
authored
Create 424-Longest-Repeating-Character-Replacement.py
1 parent 83a10ab commit a073aef

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def characterReplacement(self, s: str, k: int) -> int:
3+
count = {}
4+
res = 0
5+
6+
l = 0
7+
maxf = 0
8+
for r in range(len(s)):
9+
count[s[r]] = 1 + count.get(s[r], 0)
10+
maxf = max(maxf, count[s[r]])
11+
12+
if (r - l + 1) - maxf > k:
13+
count[s[l]] -= 1
14+
l += 1
15+
16+
res = max(res, r - l + 1)
17+
return res

0 commit comments

Comments
 (0)