1119. Remove Vowels from a String - Easy
Posted fatttcat
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1119. Remove Vowels from a String - Easy相关的知识,希望对你有一定的参考价值。
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
class Solution public String removeVowels(String S) Set<Character> set = new HashSet<>(); set.add(‘a‘); set.add(‘e‘); set.add(‘i‘); set.add(‘o‘); set.add(‘u‘); char[] chs = S.toCharArray(); int i = 0, j = 0; while(j < chs.length) if(set.contains(chs[j])) j++; else chs[i++] = chs[j++]; return new String(chs, 0, i);
以上是关于1119. Remove Vowels from a String - Easy的主要内容,如果未能解决你的问题,请参考以下文章
26Remove Duplicates from Sorted Array
26. Remove Duplicates from Sorted Array
#26 Remove Duplicates from Sorted Array