File tree Expand file tree Collapse file tree 2 files changed +19
-32
lines changed Expand file tree Collapse file tree 2 files changed +19
-32
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- class Solution {
2
- public List <List <String >> groupAnagrams (String [] strs ) {
3
- List <List <String >> res = new ArrayList <>();
4
- if (strs .length ==0 ) return res ;
5
- HashMap <String , List <String >> map = new HashMap ();
6
- for (String s : strs ){
7
- char [] hash = new char [26 ];
8
- for (char c : s .toCharArray ()){
9
- hash [c -'a' ]++;
10
- }
11
- String str =new String (hash );
12
- if (map .get (str )==null ){
13
- map .put (str , new ArrayList <>());
14
- }
15
- map .get (str ).add (s );
16
- }
17
- res .addAll (map .values ());
18
- return res ;
19
- }
1
+ class Solution {
2
+ public List <List <String >> groupAnagrams (String [] strs ) {
3
+ List <List <String >> res = new ArrayList <>();
4
+ if (strs .length ==0 ) return res ;
5
+ HashMap <String , List <String >> map = new HashMap ();
6
+ for (String s : strs ){
7
+ char [] hash = new char [26 ];
8
+ for (char c : s .toCharArray ()){
9
+ hash [c -'a' ]++;
10
+ }
11
+ String str =new String (hash );
12
+ if (map .get (str )==null ){
13
+ map .put (str , new ArrayList <>());
14
+ }
15
+ map .get (str ).add (s );
16
+ }
17
+ res .addAll (map .values ());
18
+ return res ;
19
+ }
20
20
}
You can’t perform that action at this time.
0 commit comments