terrible brute force in JS got 93% ?


  • 0
    var canConstruct = function(ransomNote, magazine) {
     
         var  ransomNote =  ransomNote.split('')  ,  magazine =  magazine.split('') 
        
        for (var i = 0 ; i < ransomNote.length  ; i++ ){
             
                 if (  CutMagazine ( ransomNote[i] , magazine  )  ==false  )
                        return false ; 
        }
        
          
        return true ; 
        
        
        
    };
    
    
    var CutMagazine  = function (  r , m ){
        
          for (var i = 0 ; i < m.length  ; i++ ){
                      if( m[i] ==r  ) 
                      {  m[i] = null ;  return true;}
                       
                     
                
          }
        
          return false ; 
        
        
        
    };
    
    //"You are here! 
    //Your runtime beats 93.48 % of javascript submissions."
    
    // My bf code is toxic trash but got 93%......Am I alone on this? 
    
    

Log in to reply
 

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