LC 345. Reverse Vowels of a String

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    string reverseVowels(string s) {
        string vowel_store;
        string vowel = "aeiouAEIOU";
        for(int i=0;i<s.size();i++)
            if(find(vowel.begin(),vowel.end(),s[i])!=vowel.end())
                vowel_store.push_back(s[i]);
        int j = vowel_store.size()-1;
        for(int i=0;i<s.size();i++)
            if(find(vowel.begin(),vowel.end(),s[i])!=vowel.end())
                s[i] = vowel_store[j--];
        return s;
    }
};


Dicussion Forum