Another 8ms C solution


  • 0
    M

    '''
    #include <string.h>
    char* reverseVowels(char* s) {
    int strSize=strlen(s);
    char *out=malloc(strSize+1);
    int idex=0;
    for (int i=0;i<strSize;i++)
    {
    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')
    out[idex++]=s[i];
    }
    idex-=1;
    for (int i=0;i<strSize;i++)
    {
    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[i]=out[idex--];
    }
    return s;
    }
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.