leetcode395】的更多相关文章

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"…
分治法. public class Solution { private int LongestSubstringSub(string s, int k, int start, int end) { if (start > end) { ; } ]; for (int i = start; i <= end; i++) { count[s[i] - 'a']++; } ; i < ; i++) { && count[i] < k) { var pos = s.Ind…
思路: 尺取法. 循环i:1~26,分别计算恰好包含i种字母并且每种字母出现的次数大于等于k个的最长子串长度. 没法直接使用尺取法,因为不满足区间单调性,但是使用如上的方法却是可以的,因为子串中包含的字母种类数是满足区间单调性的. 实现: #include <bits/stdc++.h> using namespace std; class Solution { public: int longestSubstring(string s, int k) { int n = s.length()…