Https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/discuss/87739/Java-Strict-O (N)-Two-pointer-Solution
Window contains 1-26 unique letters, respectively. Find the oldest sequence of at least K repeating ones of the letter with the length, and take the maximum value.
1 class solution {2 Public int longestsubstring (string S, int K) {3 if (S. length () <k) return 0; 4 int max = 0; 5 for (INT I = 0; I <26; I ++) {6 int [] arr = new int [26]; 7 int unique = 0; 8 int Lo = 0, HI = 0; 9 While (Hi <S. length () {10 Boolean valid = true; 11 if (ARR [S. charat (HI)-'a'] ++ = 0) Unique ++; 12 Hi ++; 13 while (unique> I) {// obtain unique = i14 if (ARR [S. charat (Lo ++)-'a'] -- = 1) Unique --; 15} 16 for (Int J = 0; j <26; j ++) {// check whether the memory does not exist but the number of letters less than K 17 if (ARR [J]> 0 & arr [J] <K) {// note that arr [J]> 0 must be 18 valid = false; 19 break; 20} 21} 22 if (unique = I & valid) {23 max = math. max (max, Hi-Lo); // The hi-lo24} 25 26} 27} 28 return Max; 29} 30}
395. Longest substring with at least K repeating characters