Substring with Concatenation of All Words
https://leetcode.com/problems/substring-with-concatenation-of-all-words/
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.
For example, given: s: "barfoothefoobarman" words: ["foo", "bar"]
You should return the indices: [0,9]. (order does not matter).
Similar problems:
- Longest Substring Which Contains 2 Unique Characters
http://www.programcreek.com/2013/02/longest-substring-which-contains-2-unique-characters/
- Longest Substring Which Contains at most k Unique Characters
- Longest Substring Without Repeating Characters
- Minimum Window Substring
Solution:
public List<Integer> findSubstring(String s, String[] words) { ArrayList<Integer> result = new ArrayList<Integer>(); if(s==null||s.length()==0||words==null||words.length==0){ return result; } //frequency of words HashMap