Reverse Vowels of a String, reversevowels
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 char* reverseVowels(char* s) { 2 int i; 3 int j; 4 char temp; 5 i = 0; 6 j = strlen(s) - 1; 7 while(i < j){ 8 9 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')10 i++;11 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')12 j--;13 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'))14 {15 temp = s[i];16 s[i] = s[j];17 s[j] = temp;18 i++;19 j--;20 }21 22 }23 return s;24 }