Reverse Vowels of a String
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".
/*************************************************************************
> File Name: LeetCode345.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Tue 10 May 2016 08:55:33 PM CST
************************************************************************/ /************************************************************************* Reverse Vowels of a String 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". ************************************************************************/ #include <stdio.h> int isVowels( char s )
{
int flag = ;
if( s=='a' || s=='e' || s=='i' || s=='o' || s=='u' || s=='A' || s=='E' || s=='I' || s=='O' || s=='U' )
{
flag = ;
}
return flag;
} char* reverseVowels( char* s )
{
int left = ;
int right = strlen(s) - ; printf("%c %c\n", s[left], s[right]);
char temp; while( left < right )
{
printf("%d %d\n", left, right);
if( isVowels(s[left]) == )
{
if( isVowels(s[right]) == )
{
temp = s[left];
s[left] = s[right];
s[right] = temp; left ++;
right--;
printf("%s\n", s);
}
else
{
right--;
}
}
else
{
left ++;
}
}
return s;
} int main()
{
char* s = "leetcode";
printf("%s\n", s);
char* reverseS = reverseVowels(s);
printf("%s\n", s); return ;
}