"Leetcode80" Reverse vowels of a String (vowel letter flashbacks)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.