C 6ms solution


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

Log in to reply
 

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