-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1119-RemoveVowelsFromAString.go
More file actions
38 lines (31 loc) · 1000 Bytes
/
1119-RemoveVowelsFromAString.go
File metadata and controls
38 lines (31 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
// 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.
import "fmt"
func removeVowels(s string) string {
res := []byte{}
isVowel := func(c byte) bool { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' }
for i := 0; i < len(s); i++ {
if !isVowel(s[i]) { res = append(res, s[i]) }
}
return string(res)
}
func main() {
// Example 1:
// Input: s = "leetcodeisacommunityforcoders"
// Output: "ltcdscmmntyfrcdrs"
fmt.Println(removeVowels("leetcodeisacommunityforcoders")) // "ltcdscmmntyfrcdrs"
// Example 2:
// Input: s = "aeiou"
// Output: ""
fmt.Println(removeVowels("aeiou")) // ""
}