Longest Substring with At Most K Distinct Characters(模板)
Longest Substring with At Most K Distinct Characters
Given a strings, find the length of the longest substring T that contains at most k distinct characters.
Example
For example, Given s ="eceba"
,k = 3
,
T is"eceb"
which its length is4
.
Challenge
O(n), n is the size of the strings.
分析
count 记录distinct 数目,所以是 while cnt > k
start的while 条件是while counter>k 不是counter+=k
Last updated