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: ""

 

Constraints:

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

Rust Solution

struct Solution;

impl Solution {
    fn remove_vowels(s: String) -> String {
        s.chars()
            .filter(|&c| !matches!(c, 'a' | 'e' | 'i' | 'o' | 'u'))
            .collect()
    }
}

#[test]
fn test() {
    let s = "leetcodeisacommunityforcoders".to_string();
    let t = "ltcdscmmntyfrcdrs".to_string();
    assert_eq!(Solution::remove_vowels(s), t);
}

Having problems with this solution? Click here to submit an issue on github.