java.lang.Object
g2001_2100.s2063_vowels_of_all_substrings.Solution

public class Solution extends Object
2063 - Vowels of All Substrings.<p>Medium</p> <p>Given a string <code>word</code>, return <em>the <strong>sum of the number of vowels</strong> (</em><code>'a'</code>, <code>'e'</code><em>,</em> <code>'i'</code><em>,</em> <code>'o'</code><em>, and</em> <code>'u'</code><em>)</em> <em>in every substring of</em> <code>word</code>.</p> <p>A <strong>substring</strong> is a contiguous (non-empty) sequence of characters within a string.</p> <p><strong>Note:</strong> 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> <p><strong>Input:</strong> word = &ldquo;aba&rdquo;</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> All possible substrings are: &ldquo;a&rdquo;, &ldquo;ab&rdquo;, &ldquo;aba&rdquo;, &ldquo;b&rdquo;, &ldquo;ba&rdquo;, and &ldquo;a&rdquo;.</p> <ul> <li> <p>&ldquo;b&rdquo; has 0 vowels in it</p> </li> <li> <p>&ldquo;a&rdquo;, &ldquo;ab&rdquo;, &ldquo;ba&rdquo;, and &ldquo;a&rdquo; have 1 vowel each</p> </li> <li> <p>&ldquo;aba&rdquo; has 2 vowels in it</p> </li> </ul> <p>Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word = &ldquo;abc&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> All possible substrings are: &ldquo;a&rdquo;, &ldquo;ab&rdquo;, &ldquo;abc&rdquo;, &ldquo;b&rdquo;, &ldquo;bc&rdquo;, and &ldquo;c&rdquo;.</p> <ul> <li> <p>&ldquo;a&rdquo;, &ldquo;ab&rdquo;, and &ldquo;abc&rdquo; have 1 vowel each</p> </li> <li> <p>&ldquo;b&rdquo;, &ldquo;bc&rdquo;, and &ldquo;c&rdquo; have 0 vowels each</p> </li> </ul> <p>Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> word = &ldquo;ltcd&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There are no vowels in any substring of &ldquo;ltcd&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= word.length <= 10<sup>5</sup></code></li> <li><code>word</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countVowels

      public long countVowels(String word)