159 Longest Substring with At Most Two Distinct Characters
1. Question
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.
For example, Given s =“eceba”
,
T is "ece" which its length is 3.
2. Implementation
(1) Two Pointer + Hash
3. Time & Space Complexity
Two Pointer + Hash: 时间复杂度O(n), 空间复杂度O(1)
Last updated