Skip to content

Commit cb66bbf

Browse files
Solve : Longest Repeating Character Replacement
1 parent 5346623 commit cb66bbf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def characterReplacement(self, s, k):
3+
count = [0] * 26
4+
left = 0
5+
max_count = 0
6+
res = 0
7+
for right in range(len(s)):
8+
count[ord(s[right]) - ord('A')] += 1
9+
max_count = max(max_count, count[ord(s[right]) - ord('A')])
10+
while (right - left + 1) - max_count > k:
11+
count[ord(s[left]) - ord('A')] -= 1
12+
left += 1
13+
res = max(res, right - left + 1)
14+
return res

0 commit comments

Comments
 (0)