1 Star 0 Fork 0

徐长贺/Leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_1119.java 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Fisher Coder 提交于 5年前 . add 1119
package com.fishercoder.solutions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* 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: "leetcodeisacommunityforcoders"
* Output: "ltcdscmmntyfrcdrs"
*
* Example 2:
* Input: "aeiou"
* Output: ""
*
* Note:
* S consists of lowercase English letters only.
* 1 <= S.length <= 1000
* */
public class _1119 {
public static class Solution1 {
public String removeVowels(String S) {
Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
StringBuilder stringBuilder = new StringBuilder();
for (char c : S.toCharArray()) {
if (!vowels.contains(c)) {
stringBuilder.append(c);
}
}
return stringBuilder.toString();
}
}
public static class Solution2 {
public String removeVowels(String S) {
return S.replaceAll("[aeiou]", "");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/isulong/Leetcode.git
git@gitee.com:isulong/Leetcode.git
isulong
Leetcode
Leetcode
master

搜索帮助