reverse vowel of string

https://leetcode.com/problems/reverse-vowels-of-a-string/description/

class Solution {
public:
    string reverseVowels(string s) {
        int left = 0;
        int right = s.size()-1;
        while(left<right){
            left = s.find_first_of("aeiouAEIOU",left);// second arg **left** is the search start pos
            right = s.find_last_of("aeiouAEIOU",right);
            if(left<right){
                swap(s[left++],s[right--]);
                //left++ in order to move the search start pos
            }
        }
        return s;
    }
};

REF:

results matching ""

    No results matching ""