-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeVowels.java
51 lines (37 loc) · 1.05 KB
/
removeVowels.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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: ""
class Solution {
public String removeVowels(String S) {
if(S == null){
return null;
}
HashSet<Character> map = new HashSet<>();
List<Character> list = new ArrayList<>();
map.add('a');
map.add('A');
map.add('e');
map.add('E');
map.add('i');
map.add('I');
map.add('o');
map.add('O');
map.add('u');
map.add('U');
char[] temp = S.toCharArray();
for(int i=0; i<=temp.length -1; i++){
if(!map.contains(temp[i])){
list.add(temp[i]);
}
}
String myString = "";
for (Character c : list) {
myString += c;
}
return myString;
}
}