Title Description: Write a function that implements the input of a string, and then turn the vowel letters into a flashback
Vowels contain case, vowel letters have five a,e,i,o,u
Original Description:
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "Hello", Return "Holle".
Example 2:
Given s = "Leetcode", Return "Leotcede".
Note:
The vowels does not include the letter "Y".
Ideas:
- 10 Characters of data structure stored by using HashSet
- Iterate through the string, using the int "s.length" to record the position of the vowel, the number of vowels is n
- Iterate through the string, replacing all vowels (indexed as I) with the characters at String.charat (N-i-1), based on the previous array
Code:
Public class solution { PublicString Reversevowels (string s) {if(s = =NULL){return NULL; }int[] Array =New int[S.length ()];int Index=0; hashset<character> Vowel =NewHashset<character> (); Vowel.add (' A '); Vowel.add (' E '); Vowel.add (' I '); Vowel.add (' O '); Vowel.add (' u '); Vowel.add (' A '); Vowel.add (' E '); Vowel.add (' I '); Vowel.add (' O '); Vowel.add (' U '); for(inti =0; I < s.length (); i++) {if(Vowel.contains (S.charat (i))) {array[Index] = i;Index++; } }Char[] result =New Char[S.length ()]; result = S.tochararray (); for(inti =0; I <Index; i++) {Result[array[i]] = S.charat (array[IndexI1]); }returnString.valueof (result); }}
For more Leetcode classic algorithms, check out my Leetcode column with the following links:
Leetcode column
My QR code is as follows, welcome to exchange discussion
You are welcome to pay attention to the "It question summary" subscription number. Every day to push the classic face test and interview tips, are dry! The QR code of the subscription number is as follows:
"Leetcode80" Reverse vowels of a String (vowel letter flashbacks)