<p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>

<p>The vowels are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>, and they can appear in both lower and upper cases, more than once.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;IceCreAm&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;AceCreIm&quot;</span></p>

<p><strong>Explanation:</strong></p>

<p>The vowels in <code>s</code> are <code>[&#39;I&#39;, &#39;e&#39;, &#39;e&#39;, &#39;A&#39;]</code>. On reversing the vowels, s becomes <code>&quot;AceCreIm&quot;</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;leetcode&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;leotcede&quot;</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>5</sup></code></li>
	<li><code>s</code> consist of <strong>printable ASCII</strong> characters.</li>
</ul>


class Solution {
public:
    string reverseVowels(string s) {
        int i = 0, j = s.size()-1;
        unordered_set<char> vovels;
        vovels.insert('a');
        vovels.insert('e');
        vovels.insert('i');
        vovels.insert('o');
        vovels.insert('u');
        vovels.insert('A');
        vovels.insert('E');
        vovels.insert('I');
        vovels.insert('O');
        vovels.insert('U');

        while(i < j)
        {
            while(vovels.find(s[i]) == vovels.end() && i < s.size()-1) {
                i++;
                // cout <<  "i: "<< i << endl;
            }
            while(vovels.find(s[j]) == vovels.end() && j > 0) {
                j--;
                // cout <<  "j: "<< j << endl;
            }
            if(i < j) {
                swap(s[i], s[j]);
                i++;
                j--;
            }

        }  
        return s;  
    }
};
10700