Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.37 KB

File metadata and controls

53 lines (40 loc) · 1.37 KB

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.

Companies:
Amazon

Related Topics:
String

Similar Questions:

Solution 1.

// OJ: https://leetcode.com/problems/remove-vowels-from-a-string/
// Author: github.com/lzl124631x
// Time: O(N)
// Space: O(1) extra space
class Solution {
public:
    string removeVowels(string s) {
        string ans;
        for (char c : s) {
            if (c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u') ans += c;
        }
        return ans;
    }
};