Longest Substring with At Most Two Distinct Characters
Hard
Given a string s
, find the length of the longest substring t
that contains at most 2
distinct characters.
Example 1:
Example 2:
Related Problems
Longest Substring with At Most K Distinct Characters
Analysis
Same as Longest Substring with At Most K Distinct Characters, when k = 2.
Sliding window two pointer technique.
Solution
Sliding Window - Two Pointers (15 ms, faster than 22.97%)
Reference
Last updated