跳转到内容

1119. Remove Vowels from a String 删去字符串中的元音


题目地址:https://leetcode-cn.com/problems/remove-vowels-from-a-string/

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

Example 1:

Input: "leetcodeisacommunityforcoders"
Output: "ltcdscmmntyfrcdrs"

Example 2:

Input: "aeiou"
Output: ""

Note:

  1. S consists of lowercase English letters only.
  2. 1 <= S.length <= 1000

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

判断是否是元音字符,决定是否加入结果中。

C++代码如下:

class Solution {
public:
string removeVowels(string S) {
string res;
for (char c : S) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
continue;
res += c;
}
return res;
}
};

2019 年 9 月 18 日 —— 今日又是九一八

最近更新:

评论与交流