My Javascript Solution


  • 0
    3
    var reverseVowels = function(s) {
         var hs = {'a':1,'e':1,'i':1,'o':1,'u':1,'A':1,'E':1,'I':1,'O':1,'U':1};
        var p = 0 , q = s.length-1;
        var str = s.split("");
        while(p<q){
            if(hs.hasOwnProperty(str[p])&&hs.hasOwnProperty(str[q])){
                var temp = str[p];
                str[p] = str[q];
                str[q] = temp;
                 p++;
                q--;
            }
            if(!hs.hasOwnProperty(str[p])){
                p++;
            }
            if(!hs.hasOwnProperty(str[q])){
                q--;
            }
        }
        return str.join("");
    };
    
    

Log in to reply
 

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