-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupAnagramsTest.java
More file actions
70 lines (61 loc) · 1.56 KB
/
GroupAnagramsTest.java
File metadata and controls
70 lines (61 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class GroupAnagramsTest {
GroupAnagrams solver = new GroupAnagrams();
@Test
public void test1() {
String[] strs = {"abc", "bca", "aac", "cab", "bba"};
Arrays.sort(strs);
System.out.println(Arrays.toString(strs));
// [aac, abc, bba, bca, cab]
}
@Test
public void test2() {
String[] strs = {"abc", "bca", "aac", "cab", "bba"};
for(String str: strs) {
char[] array = str.toCharArray();
Arrays.sort(array);
System.out.println(array);
/**
* abc
* abc
* aac
* abc
* abb
*/
}
}
@Test
public void test3() {
String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
List<List<String>> res = solver.groupAnagrams(strs);
for(List<String> l: res) {
System.out.println(l);
}
/**
* [eat, tea, ate]
* [bat]
* [tan, nat]
*/
}
@Test
public void test4() {
String[] strs = {""};
List<List<String>> res = solver.groupAnagrams(strs);
for(List<String> l: res) {
System.out.println(l);
}
// []
}
@Test
public void test5() {
String[] strs = {"a"};
List<List<String>> res = solver.groupAnagrams(strs);
for(List<String> l: res) {
System.out.println(l);
}
// [a]
}
}