Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"
Q: A: 分治,对于字符串s的任何一个字符,如果它的频数(在s中出现的次数)小于k,则它一定不会出现在最后的结果里,也就是从它的位置一劈两半,考察左右.对于当前字符串s,我们先建立字典统计其中每种字符出现的次数,对于某字符,假设为x,x在当前字符串中出现的次数小于为kk,kk<k.则所有的字符x可将当前字符串s切片为kk+1个子串,递归对这kk+1个子串进行考察即可. class Solution { public: int longestSubstring(string s, int k)
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.