[Java/C++/Python] Easy and Concise O(n)
Explanation\nFor each vowels s[i],\nit could be in the substring starting at s[x] and ending at s[y],\nwhere 0 <= x <= i and i <= y < n,\nthat is (i + 1) choice
# **Explanation**\nFor each vowels `s[i]`,\nit could be in the substring starting at `s[x]` and ending at `s[y]`,\nwhere `0 <= x <= i` and `i <= y < n`,\nthat is `(i + 1)` choices for `x`  and `(n - i)` choices for `y`.\n\nSo there are `(i + 1) * (n - i)` substrings containing `s[i]`.\n<br>\n\n\n# **Complexity**\nTime `O(n)`\nSpace `O(1)`\nCand use a const `"aeiou"` to save the space cost.\n<br>\n\n**Java**\n```java\n    public long countVowels(String s) {\n        long res = 0, n = s.length();\n        for (int i = 0; i < n; ++i)\n            if ("aeiou".indexOf(s.charAt(i)) >= 0)\n                res += (i + 1) * (n - i);\n        return res;\n    }\n```\n\n**C++**\n```cpp\n    long long countVowels(string s) {\n        long res = 0, n = s.size();\n        for (int i = 0; i < n; ++i)\n            if (string("aeiou").find(s[i]) != string::npos)\n                res += (i + 1) * (n - i);\n        return res;\n    }\n```\n\n**Python**\n```py\n    def countVowels(self, s):\n        return sum((i + 1) * (len(s) - i) for i, c in enumerate(s) if c in \'aeiou\')\n```\n
[]