classSolution{publicintlongestSubstring(String s,int k){if(k ==1){return s.length();}if(s.length()< k){return0;}// 存储出现的字符及每个字符的出现次数int[] charArr =newint[26];for(int i =0; i < s.length(); i++){int idx = s.charAt(i)-'a';
charArr[idx]++;}for(int i =0; i <26; i++){if(charArr[i]==0|| charArr[i]>= k){continue;}char c =(char)(i +97);int res =0;for(String sub : s.split(String.valueOf(c))){
res =Math.max(longestSubstring(sub, k), res);}return res;}return s.length();}}