Reverse Vowels of a String

时间:2022-05-29 04:33:55

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".

 char* reverseVowels(char* s) {
int i;
int j;
char temp;
i = ;
j = strlen(s) - ;
while(i < j){ if(s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'A' && s[i] != 'E' && s[i] != 'I' && s[i] != 'O' && s[i] != 'U')
i++;
if(s[j] != 'a' && s[j] != 'e' && s[j] != 'i' && s[j] != 'o' && s[j] != 'u' && s[j] != 'A' && s[j] != 'E' && s[j] != 'I' && s[j] != 'O' && s[j] != 'U')
j--;
if((s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o'|| s[i] == 'u' || s[i] == 'A' || s[i] == 'E'|| s[i] == 'I'|| s[i] == 'O'|| s[i] == 'U') && (s[j] == 'a' || s[j] == 'e' || s[j] == 'i' || s[j] == 'o'|| s[j] == 'u' || s[j] == 'A' || s[j] == 'E'|| s[j] == 'I'|| s[j] == 'O'|| s[j] == 'U'))
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
i++;
j--;
} }
return s;
}