Skip to content

Commit 498f3de

Browse files
add 1119
1 parent 89c55d1 commit 498f3de

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Your ideas/fixes/algorithms are more than welcome!
3939
|1137|[N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1137.java) | O(n) | O(n) | |Easy||
4040
|1122|[Relative Sort Array](https://leetcode.com/problems/relative-sort-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1122.java) | O(n) | O(n) | |Easy||
4141
|1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1170.java) | | | |Easy||
42+
|1119|[Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1119.java) | | | |Easy||
4243
|1089|[Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1089.java) | O(n^2) | O(1) | |Easy||
4344
|1079|[Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1079.java) | O(1) | O(1) | |Medium||
4445
|1078|[Occurrences After Bigram](https://leetcode.com/problems/occurrences-after-bigram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1078.java) | O(n) | O(1) | |Easy||
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
/**
8+
* 1119. Remove Vowels from a String
9+
*
10+
* Given a string S, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.
11+
*
12+
* Example 1:
13+
* Input: "leetcodeisacommunityforcoders"
14+
* Output: "ltcdscmmntyfrcdrs"
15+
*
16+
* Example 2:
17+
* Input: "aeiou"
18+
* Output: ""
19+
*
20+
* Note:
21+
* S consists of lowercase English letters only.
22+
* 1 <= S.length <= 1000
23+
* */
24+
public class _1119 {
25+
public static class Solution1 {
26+
public String removeVowels(String S) {
27+
Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
28+
StringBuilder stringBuilder = new StringBuilder();
29+
for (char c : S.toCharArray()) {
30+
if (!vowels.contains(c)) {
31+
stringBuilder.append(c);
32+
}
33+
}
34+
return stringBuilder.toString();
35+
}
36+
}
37+
38+
public static class Solution2 {
39+
public String removeVowels(String S) {
40+
return S.replaceAll("[aeiou]", "");
41+
}
42+
}
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1119;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1119Test {
10+
private static _1119.Solution1 solution1;
11+
private static _1119.Solution2 solution2;
12+
private static String S;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _1119.Solution1();
17+
solution2 = new _1119.Solution2();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
S = "leetcodeisacommunityforcoders";
23+
assertEquals("ltcdscmmntyfrcdrs", solution1.removeVowels(S));
24+
assertEquals("ltcdscmmntyfrcdrs", solution2.removeVowels(S));
25+
}
26+
27+
@Test
28+
public void test2() {
29+
S = "aeiou";
30+
assertEquals("", solution1.removeVowels(S));
31+
assertEquals("", solution2.removeVowels(S));
32+
}
33+
34+
}

0 commit comments

Comments
 (0)