The vowel-letter reversal in a string
345. Reverse vowels of a StringQuestionEditorial SolutionMy Submissions
- Total accepted:31038
- Total submissions:86077
- Difficulty:easy
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".//1. E and E exchange; 2. E and O Exchange
Note:
The vowels does not include the letter "Y".
Subscribe to see which companies asked this question
1 Char* Reversevowels (Char*s) {2 3 intLeft,right;4 Chartmp;5 6 Chara[Ten]={'a','e','I','o','u','A','E','I','O','U'};7 Char*tmp_a;8Tmp_a =A;9 intI=0;Ten Oneleft =0; Aright = strlen (s)-1; - - the //Both sides move the pointer assignment at the same time - while(Left <Right ) { -TMP =S[left]; - //left judgment + while(I <Ten){ - if(tmp_a[i++] = =S[left]) { +i =0; A Break; at } - - } - - if(I! =0){ -left++; ini =0;//back to start position - Continue; to } + //Right judgment . - while(I <Ten){ the if(tmp_a[i++] = =S[right]) { *i =0; $ Break;Panax Notoginseng } - } the + if(I! =0){ Aright--; thei =0;//back to start position + Continue; - } $ $ //tmp = S[left]; -S[left] =S[right]; -S[right] =tmp; theleft++; -right--;Wuyii =0; the } - Wu returns; - About}
View Code
Vowel-Letter reversal output in a string