Memory Limit Exceeded ?How to modify?


  • 0
    W
     /**
      * @param {string} s
      * @return {string}
      */
    
    
     var reverseVowels = function(s) {
         var len = s.length,
             right = len - 1,
             left = 0;
    
         while(left < right) {
             var leftFlag = isVowels(s.charAt(left)),
                 rightFlag = isVowels(s.charAt(right));
    
             if( leftFlag && rightFlag ) {
                 s = s.substring(0,left) +  s.charAt(right) + s.substring(left+1,right) + s.charAt(left) + s.substring(right+1,len);
    
                 left++;
                 right--;
             } else if(leftFlag) {
                 right--;
             } else if(rightFlag) {
                 left++;
             } else{
                 left++;
                 right--;
             }
         }
    
         return s;
    
     };
    
     function isVowels(letter){
         if ('a' == letter || 'e' == letter || 'i' == letter || 'o' == letter || 'u' == letter || 'A' == letter || 'E' == letter || 'I' == letter || 'O' == letter || 'U' == letter) {
             return true;
         }
         return false;
     }
    

Log in to reply
 

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