@@ -0,0 +1,1919 @@
+/***%0A * You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.%0A *%0A * For example, given:%0A * S: %22barfoothefoobarman%22%0A * L: %5B%22foo%22, %22bar%22%5D%0A *%0A * You should return the indices: %5B0,9%5D.%0A * (order does not matter).%0A */%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0A%0Apublic class Solution %7B%0A    // O(n * m) O(m)%0A    public List%3CInteger%3E findSubstring(String S, String%5B%5D L) %7B%0A        List%3CInteger%3E ret = new ArrayList%3CInteger%3E();%0A        if (L.length == 0 %7C%7C L.length * L%5B0%5D.length() %3E S.length()) return ret;%0A%0A        HashMap%3CString, Integer%3E map = new HashMap%3CString, Integer%3E();%0A        for (String s : L)%0A            map.put(s, map.containsKey(s) ? map.get(s).intValue() + 1 : 1);%0A        %0A        int index = 0;%0A        for (int start = 0, end = L.length * L%5B0%5D.length() - 1;%0A                end %3C S.length(); start++, end++) %7B%0A            index = check(S, start, end, L.length, L%5B0%5D.length(),%0A                    L, map);%0A            if (index %3E -1) ret.add(index);%0A        %7D%0A        return ret;%0A    %7D%0A%0A    private int check (String s, int start, int end, int m, int n, String%5B%5D L, HashMap%3CString, Integer%3E map) %7B%0A        HashMap%3CString, Integer%3E used = new HashMap%3CString, Integer%3E();%0A        int idx = start;%0A        while (idx %3C= end) %7B%0A            String str = s.substring(idx, idx + n);%0A            if (map.containsKey(str)) %7B%0A                if (used.containsKey(str)) %7B%0A                    int i = used.get(str);%0A                    if (i == map.get(str))%0A                        return -1;%0A                    else%0A                        used.put(str, i + 1);%0A                %7D else%0A                    used.put(str, 1);%0A                idx += n;%0A            %7D else%0A                return -1;%0A        %7D%0A        return start;%0A    %7D%0A%7D%0A

add SubstringwithConcatenationofAllWords.java