MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / groupAnagrams

Method groupAnagrams

LeetCode_problems/Anagrams/Solution.java:21–39  ·  view source on GitHub ↗
(String[] strs)

Source from the content-addressed store, hash-verified

19import java.util.*;
20class Solution {
21 public List<List<String>> groupAnagrams(String[] strs){
22 List<List<String>> list = new ArrayList<List<String>>();
23 HashMap<String,Integer> set = new HashMap<>();
24 int j = 0;
25 for(int i=0;i<strs.length;++i){
26 char c[]= strs[i].toCharArray();
27 Arrays.sort(c);
28 String s = new String(c);
29 if(set.containsKey(s)){
30 list.get(set.get(s)).add(strs[i]);
31 }
32 else{
33 list.add(new ArrayList<String>());
34 set.put(s,j++);
35 list.get(set.get(s)).add(strs[i]);
36 }
37 }
38 return list;
39 }
40}

Callers

nothing calls this directly

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected