标签:rar remove else move string contain put not and
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
标签:rar remove else move string contain put not and
原文地址:https://www.cnblogs.com/fatttcat/p/11331156.html