Leetcode30.串联所有单词的子串

代码:(差一个用例超时qaq

class Solution {
    public List findSubstring(String s, String[] words) {
        List res = new ArrayList<>();
        int len = words.length * words[0].length();
        for(int i=0;i<=s.length()-len;i++){
            if(f(s.substring(i,i+len),words)){
                res.add(i);
            }
        }
        return res;
    }
    public boolean f(String sub,String[] words){
        List list = new ArrayList<>();
        for(String word:words){
            if(!sub.contains(word))return false;
            list.add(word);
        }
        for(int i=0;i iterator = list.iterator();
            while(iterator.hasNext()){
                String word = iterator.next();
                if(sub2.equals(word)){
                    ff=true;
                    iterator.remove();
                    break;
                }
            }
            if(ff==false)return false;           
        }
        return true;
    }
}

你可能感兴趣的:(开发语言)