The main idea is to maintain a sliding window with 2 unique characters.
The key is to store the last occurrence of each character as the value in the hashmap.
https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/description/
No comments:
Post a Comment