simple C solution,in one function


  • 0
    W
    char* reverseVowels(char* s) {
        int i=0,j=strlen(s)-1;
        char *tmp="aeiouAEIOU";
        while(i<j){
        	char *t1=strchr(tmp,*(s+i));
        	char *t2=strchr(tmp,*(s+j));
        	if(t1 && t2){
        		char t=*(s+i);
        		*(s+i++)=*(s+j);
        		*(s+j--)=t;
        	}
        	else if(t1 && !t2) j--;
        	else if(!t1 && t2) i++;
        	else{
        		i++;
        		j--;
        	}
        }
        return s;
    }
    

Log in to reply
 

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