Java D&C


  • 0
    C

    ...
    public class Solution {
    public int longestSubstring(String s, int k) {
    if(s.length()==0) return 0;
    int[] cnt=new int[26];
    for(int i=0;i<s.length();i++) {
    cnt[s.charAt(i)-'a']++;
    }
    for(int i=0;i<26;i++) {
    if(cnt[i]>0&&cnt[i]<k) {
    String[] set=s.split(""+(char)('a'+i));
    int max=0;
    for(String sub:set) {
    max=Math.max(max,longestSubstring(sub,k));
    }
    return max;
    }
    }
    return s.length();
    }
    }
    ....


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.