javascript solution


  • 0
    J
     * @param {string[]} strs
     * @return {string[][]}
     */
    var groupAnagrams = function(strs) {
        var res = [];
        var map = {};
        for(let i=0;i<strs.length;i++){
            var s = strs[i];
            var sorts = s.split('').sort().join('');
            if(map[sorts]===undefined){
                var list = [];
                list.push(s);
                map[sorts] = list;
            }else{
                map[sorts].push(s);
            }
        }
        for(let k in map){
            res.push(map[k]);
        }
        return res;
    };

Log in to reply
 

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