Javascript 8 lines solution using hashmap, simple and understandable


  • 1
    H

    It is very simple and cute.

    var groupAnagrams = function(strs) {
      let len = strs.length, map = {}, sortStr = '';
      for(let i = 0; i < len; i++) {
        sortStr = strs[i].split('').sort().join('');
        if(!map[sortStr])  map[sortStr] = [];
        map[sortStr].push(strs[i])
      }
      return Object.values(map);
    };
    

Log in to reply
 

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