hashtable+双指针窗口法解题思路
最近一直在刷leetcode,发现许多题目解法很相似,如求 findSubstring,minWindow,lengthOfLongestSubstring问题,解法大致都一样都是用滑动窗口的思想,不过滑动的规则没处理好,很容易导致时间复杂度增加;
题目链接:
https://leetcode.com/problems/substring-with-concatenation-of-all-words/
;
http://oj.leetcode.com/problems/minimum-window-substring/
;
http://oj.leetcode.com/problems/longest-substring-without-repeating-characters/
;
//链接1题解
public ArrayList<Integer> findSubstring(String S, String[] L) {
// Note: The Solution object is instantiated only once and is reused by each test case.
ArrayList<Integer> res = new ArrayList<Integer>();
if(S==null || S.length()==0 || L==null || L.length==0)
return res;
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int i=0;i<L.length;i++)
{
if(map.containsKey(L[i]))
{
map.put(L[i],map.get(L[i])+1);
}
else
{
map.put(L[i],1);
}
}
for(int i=0;i<L[0].
版权声明:本文为u010860412原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。