js version répondre


  • 0

    hardcore.js

    var findWords = function(words) {
      
    var rows = [['q','w','e','r','t','y','u','i','o','p'], ['a','s','d','f','g','h','j','k','l'],['z','x','c','v','b','n','m']];
         var newA = [] ; 
         for (var i=0 ; i<words.length; i++){
    
              if (checkRow( words[i],rows)== true )
              newA.push (words[i]); 
             
         };
         return newA;
         
    };
    
    
    var checkRow = function (w,rows){
        var wA = w.toLowerCase().split('');   var firstL = wA[0] ;  var inRow = 0 ;  
        for (var i=0 ; i<rows.length;i++){  
              if (rows[i].indexOf(firstL)!=-1) { inRow=i ; } ;  
              
        }; 
    
        for (var i=0 ; i<wA.length;i++){
             if ( rows[inRow].indexOf (wA[i]) == -1 ) return false ;
        }
        
        return true ; 
        
        
    }
    

Log in to reply
 

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