【leetcode】反转字符串中的元音字母

 

char * reverseVowels(char * s){
    char vowels[6] = {'a', 'e', 'i', 'o', 'u'};
    int i = 0, j = strlen(s) - 1;
    char t;
    
    while (i < j){
        if (strchr(vowels, tolower(s[i])) && strchr(vowels, tolower(s[j]))){
            t = s[i], s[i] = s[j], s[j] = t;
            i++, j--;
        }
        else if (!strchr(vowels, tolower(s[i])))
            i++;
        else if (!strchr(vowels, tolower(s[j])))
            j--;
    }
    return s;
}

 

posted @ 2020-09-07 14:41  温暖了寂寞  阅读(165)  评论(0编辑  收藏  举报