Brief C++ Solution 13ms


  • 0
    C
    class Solution {
    public:
        string reverseVowels(string s) {
            string vowels = "aeiouAEIOU";
            
            int i = 0, j = s.length()-1;
            
            while (i < j) {
                while (i < j && vowels.find(s[i]) == -1) {
                    i ++;
                }
                
                while (i < j && vowels.find(s[j]) == -1) {
                    j --;
                }
                
                char ch = s[i];
                s[i] = s[j];
                s[j] = ch;
                
                i ++;
                j --;
            }
            
            return s;
        }
    };
    

Log in to reply
 

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