<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sliding Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/sliding/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/sliding/</link>
	<description></description>
	<lastBuildDate>Mon, 28 May 2018 18:46:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>sliding Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/sliding/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 438. Find All Anagrams in a String</title>
		<link>https://zxi.mytechroad.com/blog/hashtable/leetcode-438-find-all-anagrams-in-a-string/</link>
					<comments>https://zxi.mytechroad.com/blog/hashtable/leetcode-438-find-all-anagrams-in-a-string/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 28 May 2018 14:56:31 +0000</pubDate>
				<category><![CDATA[Hashtable]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[anagram]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[sliding]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2852</guid>

					<description><![CDATA[<p>Problem 题目大意：在s中找出所有p的Anagrams。 https://leetcode.com/problems/find-all-anagrams-in-a-string/description/ Given a string s and a non-empty string p, find all the start indices of p&#8216;s anagrams in s. Strings consists of lowercase English letters only and the length&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-438-find-all-anagrams-in-a-string/">花花酱 LeetCode 438. Find All Anagrams in a String</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><iframe width="500" height="375" src="https://www.youtube.com/embed/86fQQ7rVGxA?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<h1><strong>Problem</strong></h1>
<p>题目大意：在s中找出所有p的Anagrams。</p>
<p><a href="https://leetcode.com/problems/find-all-anagrams-in-a-string/description/">https://leetcode.com/problems/find-all-anagrams-in-a-string/description/</a></p>
<p>Given a string <b>s</b> and a <b>non-empty</b> string <b>p</b>, find all the start indices of <b>p</b>&#8216;s anagrams in <b>s</b>.</p>
<p>Strings consists of lowercase English letters only and the length of both strings <b>s</b> and <b>p</b> will not be larger than 20,100.</p>
<p>The order of output does not matter.</p>
<p><b>Example 1:</b></p>
<pre class="crayon:false"><b>Input:</b>
s: "cbaebabacd" p: "abc"

<b>Output:</b>
[0, 6]

<b>Explanation:</b>
The substring with start index = 0 is "cba", which is an anagram of "abc".
The substring with start index = 6 is "bac", which is an anagram of "abc".
</pre>
<p><b>Example 2:</b></p>
<pre class="crayon:false "><b>Input:</b>
s: "abab" p: "ab"

<b>Output:</b>
[0, 1, 2]

<b>Explanation:</b>
The substring with start index = 0 is "ab", which is an anagram of "ab".
The substring with start index = 1 is "ba", which is an anagram of "ab".
The substring with start index = 2 is "ab", which is an anagram of "ab".</pre>
<h1><img class="alignnone size-full wp-image-2856" src="http://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/438-ep191.png" alt="" width="960" height="540" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/438-ep191.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/438-ep191-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/438-ep191-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></h1>
<h1><strong>Solution: HashTable + Sliding Window</strong></h1>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(n)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 35 ms
class Solution {
public:
  vector&lt;int&gt; findAnagrams(string s, string p) {
    int n = s.length();
    int l = p.length();
    vector&lt;int&gt; ans;
    vector&lt;int&gt; vp(26, 0);
    vector&lt;int&gt; vs(26, 0);
    for (char c : p) ++vp[c - 'a'];    
    for (int i = 0; i &lt; n; ++i) {
      if (i &gt;= l) --vs[s[i - l] - 'a'];        
      ++vs[s[i] - 'a'];
      if (vs == vp) ans.push_back(i + 1 - l);
    }
    return ans;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-438-find-all-anagrams-in-a-string/">花花酱 LeetCode 438. Find All Anagrams in a String</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/hashtable/leetcode-438-find-all-anagrams-in-a-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
