Another Javascript one


  • 0
    C

    ...
    /**

    • @param {string[]} words
    • @return {string[]}
      */
      var findWords = function(words) {
      var allowWords = [];
      words.forEach(function(word){
      var firstRow = word.match(/[qwertyuiop]+/i);
      var secondRow = word.match(/[asdfghjkl]+/i);
      var thirdRow = word.match(/[zxcvbnm]+/i);
      if((firstRow && firstRow.toString() === word)
      ||(secondRow && secondRow.toString() === word)
      ||(thirdRow && thirdRow.toString() === word))
      allowWords.push(word);
      });
      return allowWords;
      };
      ...

Log in to reply
 

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