public List<Integer> findSubstring(String S, String[] L) {
        Map<String, Integer> map = new HashMap<String, Integer>();
        for(String word : L){
            if(!map.containsKey(word)){
                map.put(word, 0);
            }
            map.put(word, map.get(word) + 1);
        }

        List<Integer> result = new ArrayList<Integer>();
        int wordLen = L[0].length();
        int len = L.length * wordLen;

        for(int i = 0; i <= S.length() - len; i++){
            Map<String, Integer> copy = new HashMap<String, Integer>(map);
            String sub = S.substring(i, i + len);
            while (true){
                String word = sub.substring(0, wordLen);
                if(copy.containsKey(word)){
                    int count = copy.get(word) - 1;
                    if(count < 0) break;
                    copy.put(word, count);
                    sub = sub.substring(wordLen);
                    if(sub.isEmpty()){
                        result.add(i);
                        break;
                    }
                }else{
                    break;
                }
            }
        }
        return result;
    }