Longest Substring with 2 Distinct Characters
Given a string s
, find the length of the longest substring that contains at most 2
distinct characters.
Constraints
n ≤ 10,000
wheren
is the length ofs
.
https://binarysearch.com/problems/Longest-Substring-with-2-Distinct-Characters
Examples
Example 1
Input
- s =
abccb
Output
- answer =
4
Explanation
"bccb"
is the longest substring with at most 2
distinct characters.
Leave a comment