My JS code has passed 96/100 test cases, but No.97 is TLE.. I dont know what's wrong..


  • 0
    L

    /**

    • @param {string[]} strs
    • @return {string[][]}
      */
      var groupAnagrams = function(strs) {
      var result = [];
      var temp = [];
      while (strs.length > 0){
      temp = [];
      var tempStr = strs[0];
      var lead = tempStr.split("").sort().join("");
      for (let i = 1; i < strs.length; i++){
      let p = strs[i];
      if (p.split("").sort().join("") === lead){
      temp.push(strs[i]);
      strs.splice(i,1);
      i--;
      }
      }
      temp.push(strs[0]);
      strs.splice(0,1);
      result.push(temp.slice());
      }
      return result;
      };

Log in to reply
 

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