Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 1.71 KB

File metadata and controls

80 lines (55 loc) · 1.71 KB

English Version

题目描述

给你一个字符串 s ,请你删去其中的所有元音字母 'a''e''i''o''u',并返回这个新字符串。

 

示例 1:

输入:s = "leetcodeisacommunityforcoders"
输出:"ltcdscmmntyfrcdrs"

示例 2:

输入:s = "aeiou"
输出:""

 

提示:

  • 1 <= S.length <= 1000
  • s 仅由小写英文字母组成

解法

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();
    }
}

...