12ms Simple C++ Solution


  • 0
    Y
    class Solution {
    public:
        string reverseVowels(string s) {
            int left = 0, right = s.length() - 1;
            char map[255] = {0};
            map['a'] = 1, map['e'] = 1, map['i'] = 1, map['o'] = 1, map['u'] = 1;
            map['A'] = 1, map['E'] = 1, map['I'] = 1, map['O'] = 1, map['U'] = 1;
            
            while(left < right) {
                while(map[s[left]] == 0) left++;
                while(map[s[right]] == 0) right--;
                if(left < right) swap(s[left++], s[right--]);
            }
            return s;
        }
    };
    

Log in to reply
 

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