LeetCode 1119. 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: s = "leetcodeisacommunityforcoders"
Output: "ltcdscmmntyfrcdrs"

Example 2:

Input: s = "aeiou"
Output: ""


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


Check if character is a, e, i, o or u.

Python Solution

class Solution:
    def removeVowels(self, s: str) -> str:
        result = ""
        for ch in s:
            if ch not in ('a', 'e', 'i', 'o', 'u'):
                result += ch
        return result
  • Time complexity: O(N).
  • Space complexity: O(N).

Leave a Reply

Your email address will not be published. Required fields are marked *