Example:
Input:
s = “ababbc”, k = 2
Output:
5
The longest substring is “ababb”, as ‘a’ is repeated 2 times and ‘b’ is repeated 3 times.
code:
class Solution:
def longestSubstring(self, s, k):
"""
:type s: str
:type k: int
:rtype: int
"""
for i in set(s):
if s.count(i) < k: # 找出不满足k次的字母
return max(self.longestSubstring(m, k) for m in s.split(i)) # 将其作为分割点进行分治
return len(s)