424. Longest Repeating Character Replacement
Solutions
Sliding Window with tolerance
- Keep pointer
startandcurr, a dictionary ofnum_occuranceandmax_occurance - If
curr - start + 1 - max_occurance > tolerance- Move
startto next - Update
num_occurancenum_occurance[ord(s[start]) - ord('A')] -= 1No need to update
max_occurancebecause we only expect window ≥max_occurance + k, thusstartwill only be updated whenmax_occuranceis updated bys[curr]
- Move
- return
lormax_occurance + tolerance