424. Longest Repeating Character Replacement
Solutions
Sliding Window with tolerance
- Keep pointer
start
andcurr
, a dictionary ofnum_occurance
andmax_occurance
- If
curr - start + 1 - max_occurance > tolerance
- Move
start
to next - Update
num_occurance
num_occurance[ord(s[start]) - ord('A')] -= 1
No need to update
max_occurance
because we only expect window ≥max_occurance + k
, thusstart
will only be updated whenmax_occurance
is updated bys[curr]
- Move
- return
l
ormax_occurance + tolerance