All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2001_2100.s2063_vowels_of_all_substrings.Solution Maven / Gradle / Ivy

There is a newer version: 1.35
Show newest version
package g2001_2100.s2063_vowels_of_all_substrings;

// #Medium #String #Dynamic_Programming #Math #Combinatorics
// #2022_05_29_Time_21_ms_(34.49%)_Space_48.9_MB_(68.06%)

public class Solution {
    public long countVowels(String word) {
        long ans = 0;
        for (int i = 0; i < word.length(); i++) {
            if (isVowel(word.charAt(i))) {
                long right = word.length() - (long) i - 1;
                ans += ((long) i + 1) * (right + 1);
            }
        }
        return ans;
    }

    private boolean isVowel(char ch) {
        return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy