Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.56 KB

File metadata and controls

71 lines (51 loc) · 1.56 KB

中文文档

Description

Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.

 

Example 1:

Input: s = "leetcodeisacommunityforcoders"
Output: "ltcdscmmntyfrcdrs"

Example 2:

Input: s = "aeiou"
Output: ""

 

Constraints:

  • 1 <= s.length <= 1000
  • s consists of only lowercase English letters.

Solutions

Python3

class Solution:
    def removeVowels(self, s: str) -> str:
        res = []
        for c in s:
            if c not in {'a', 'e', 'i', 'o', 'u'}:
                res.append(c)
        return ''.join(res)

Java

class Solution {
    public String removeVowels(String s) {
        StringBuilder res = new StringBuilder();
        for (char c : s.toCharArray()) {
            if (!(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')) {
                res.append(c);
            }
        }
        return res.toString();
    }
}

...