A common java solution with 32ms runtime


  • 0
    F

    '''
    public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
    Map<String,List<String>> map=new HashMap<String,List<String>>();
    for(int i=0;i<strs.length;i++){
    char[] temp=strs[i].toCharArray();
    Arrays.sort(temp);
    if(!map.containsKey(String.valueOf(temp)))
    map.put(String.valueOf(temp), new ArrayList<String>());
    map.get(String.valueOf(temp)).add(strs[i]);
    }
    return new ArrayList<List<String>>(map.values());
    }
    }
    '''


Log in to reply
 

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