<?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>vowels Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/vowels/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/vowels/</link>
	<description></description>
	<lastBuildDate>Sun, 07 Nov 2021 16:15:37 +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>vowels Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/vowels/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2063. Vowels of All Substrings</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-2063-vowels-of-all-substrings/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-2063-vowels-of-all-substrings/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 07 Nov 2021 16:14:40 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[vowels]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8679</guid>

					<description><![CDATA[<p>Given a string&#160;word, return&#160;the&#160;sum of the number of vowels&#160;('a',&#160;'e',&#160;'i',&#160;'o', and&#160;'u')&#160;in every substring of&#160;word. A&#160;substring&#160;is a contiguous (non-empty) sequence of characters within a string. Note:&#160;Due to&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2063-vowels-of-all-substrings/">花花酱 LeetCode 2063. Vowels of All Substrings</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>word</code>, return&nbsp;<em>the&nbsp;<strong>sum of the number of vowels</strong>&nbsp;(</em><code>'a'</code>,&nbsp;<code>'e'</code><em>,</em>&nbsp;<code>'i'</code><em>,</em>&nbsp;<code>'o'</code><em>, and</em>&nbsp;<code>'u'</code><em>)</em>&nbsp;<em>in every substring of&nbsp;</em><code>word</code>.</p>



<p>A&nbsp;<strong>substring</strong>&nbsp;is a contiguous (non-empty) sequence of characters within a string.</p>



<p><strong>Note:</strong>&nbsp;Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word = "aba"
<strong>Output:</strong> 6
<strong>Explanation:</strong> 
All possible substrings are: "a", "ab", "aba", "b", "ba", and "a".
- "b" has 0 vowels in it
- "a", "ab", "ba", and "a" have 1 vowel each
- "aba" has 2 vowels in it
Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6. 
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word = "abc"
<strong>Output:</strong> 3
<strong>Explanation:</strong> 
All possible substrings are: "a", "ab", "abc", "b", "bc", and "c".
- "a", "ab", and "abc" have 1 vowel each
- "b", "bc", and "c" have 0 vowels each
Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3. </pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word = "ltcd"
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no vowels in any substring of "ltcd".</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word = "noosabasboosa"
<strong>Output:</strong> 237
<strong>Explanation:</strong> There are a total of 237 vowels in all the substrings.
</pre>



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



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



<h2><strong>Solution: Math</strong></h2>



<p>For a vowel at index i, <br>we can choose 0, 1, &#8230; i as starting point<br>choose i, i+1, &#8230;, n -1 as end point.<br>There will be (i &#8211; 0 + 1) * (n &#8211; 1 &#8211; i + 1) possible substrings that contains word[i].</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">class Solution {
public:
  long long countVowels(string word) {
    const long long n = word.size();
    long long ans = 0;
    for (long long i = 0; i &lt; n; ++i) {
      switch (word[i]) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
          ans += (i + 1) * (n - 1 - i + 1);
          break;
      }
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2063-vowels-of-all-substrings/">花花酱 LeetCode 2063. Vowels of All Substrings</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/string/leetcode-2063-vowels-of-all-substrings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
