3ms c solution beat 100%


  • 0
    4

    char* reverseVowels(char* s) {
    int len;
    int i;
    int j;
    char tmp;

    len = strlen(s);
    i = 0;
    j = len - 1;
    
    while(i < j)
    {
        while(i < j && 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--;
        }
        
        while(i < j && 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(i < j)
        {
            tmp = s[i];
            s[i] = s[j];
            s[j] = tmp;
        }
        j--;
        i++;
    }
    
    return s;
    

    }


Log in to reply
 

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