159.Longest-Substring-with-At-Most-Two-Distinct-Characters
159. Longest Substring with At Most Two Distinct Characters
题目地址
https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/
题目描述
Given a string s , find the length of the longest substring t that contains at most 2 distinct characters.
Example 1:
Input: "eceba"
Output: 3
Explanation: t is "ece" which its length is 3.
Example 2:
Input: "ccaabbb"
Output: 5
Explanation: t is "aabbb" which its length is 5.代码
Approach #1 Sliding Window + HashMap
Last updated
Was this helpful?