Skip to content

Commit

Permalink
Add solution for Longest Repeating Character Replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Feb 8, 2024
1 parent 5dac994 commit 1527e3e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions camp/week1/leetcode/longest-repeating-character-replacement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
left=0
right=0
dic={}
_max=0
while right <len(s):
dic[s[right]]=dic.get(s[right],0) +1
window=right-left+1
if window - max(dic.values()) <= k:
_max=max(_max,sum(dic.values()))
else:
dic[s[left]]-= 1
if not dic[s[left]]:
del dic[s[left]]
left+=1
right+=1
return _max

0 comments on commit 1527e3e

Please sign in to comment.