<?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>vows Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/vows/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/vows/</link>
	<description></description>
	<lastBuildDate>Sun, 24 May 2020 05:30:09 +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>vows Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/vows/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1456. Maximum Number of Vowels in a Substring of Given Length</title>
		<link>https://zxi.mytechroad.com/blog/sliding-window/leetcode-1456-maximum-number-of-vowels-in-a-substring-of-given-length/</link>
					<comments>https://zxi.mytechroad.com/blog/sliding-window/leetcode-1456-maximum-number-of-vowels-in-a-substring-of-given-length/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 24 May 2020 05:28:48 +0000</pubDate>
				<category><![CDATA[Sliding Window]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[sliding window]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[vows]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6814</guid>

					<description><![CDATA[<p>Given a string&#160;s&#160;and an integer&#160;k. Return&#160;the maximum number of vowel letters&#160;in any substring of&#160;s&#160;with&#160;length&#160;k. Vowel letters&#160;in&#160;English are&#160;(a, e, i, o, u). Example 1: Input: s&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/sliding-window/leetcode-1456-maximum-number-of-vowels-in-a-substring-of-given-length/">花花酱 LeetCode 1456. Maximum Number of Vowels in a Substring of Given Length</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>Given a string&nbsp;<code>s</code>&nbsp;and an integer&nbsp;<code>k</code>.</p>



<p>Return&nbsp;<em>the maximum number of vowel letters</em>&nbsp;in any substring of&nbsp;<code>s</code>&nbsp;with&nbsp;length&nbsp;<code>k</code>.</p>



<p><strong>Vowel letters</strong>&nbsp;in&nbsp;English are&nbsp;(a, e, i, o, u).</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "abciiidef", k = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> The substring "iii" contains 3 vowel letters.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "aeiou", k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> Any substring of length 2 contains 2 vowels.
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "leetcode", k = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> "lee", "eet" and "ode" contain 2 vowels.
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "rhythms", k = 4
<strong>Output:</strong> 0
<strong>Explanation:</strong> We can see that s doesn't have any vowel letters.
</pre>



<p><strong>Example 5:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "tryhard", k = 4
<strong>Output:</strong> 1
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= s.length &lt;= 10^5</code></li><li><code>s</code>&nbsp;consists of lowercase English letters.</li><li><code>1 &lt;= k &lt;= s.length</code></li></ul>



<h2><strong>Solution: Sliding Window</strong></h2>



<p>Keep tracking the number of vows in a window of size k.</p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int maxVowels(string s, int k) {    
    vector&lt;int&gt; v(128);
    v['a'] = v['e'] = v['i'] = v['o'] = v['u'] = 1;
    int total = 0;
    int ans = 0;
    for (int i = 1; i &lt;= s.length(); ++i) {
      total += v[s[i - 1]];
      if (i &gt;= k) {
        ans = max(ans, total);
        total -= v[s[i - k]];
      }
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/sliding-window/leetcode-1456-maximum-number-of-vowels-in-a-substring-of-given-length/">花花酱 LeetCode 1456. Maximum Number of Vowels in a Substring of Given Length</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/sliding-window/leetcode-1456-maximum-number-of-vowels-in-a-substring-of-given-length/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
