|
5 | 5 | import java.util.Set;
|
6 | 6 | import java.util.stream.Collectors;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * 893. Groups of Special-Equivalent Strings |
10 |
| - * |
11 |
| - * You are given an array A of strings. |
12 |
| - * A move onto S consists of swapping any two even indexed characters of S, or any two odd indexed characters of S. |
13 |
| - * Two strings S and T are special-equivalent if after any number of moves onto S, S == T. |
14 |
| - * For example, S = "zzxy" and T = "xyzz" are special-equivalent because we may make the moves "zzxy" -> "xzzy" -> "xyzz" |
15 |
| - * that swap S[0] and S[2], then S[1] and S[3]. |
16 |
| - * |
17 |
| - * Now, a group of special-equivalent strings from A is a non-empty subset of A such that: |
18 |
| - * Every pair of strings in the group are special equivalent, and; |
19 |
| - * The group is the largest size possible (ie., there isn't a string S not in the group such that S is special equivalent to every string in the group) |
20 |
| - * Return the number of groups of special-equivalent strings from A. |
21 |
| - * |
22 |
| - * Example 1: |
23 |
| - * Input: ["abcd","cdab","cbad","xyzz","zzxy","zzyx"] |
24 |
| - * Output: 3 |
25 |
| - * Explanation: |
26 |
| - * One group is ["abcd", "cdab", "cbad"], since they are all pairwise special equivalent, and none of the other strings are all pairwise special equivalent to these. |
27 |
| - * The other two groups are ["xyzz", "zzxy"] and ["zzyx"]. Note that in particular, "zzxy" is not special equivalent to "zzyx". |
28 |
| - * |
29 |
| - * Example 2: |
30 |
| - * Input: ["abc","acb","bac","bca","cab","cba"] |
31 |
| - * Output: 3 |
32 |
| - * |
33 |
| - * Note: |
34 |
| - * 1 <= A.length <= 1000 |
35 |
| - * 1 <= A[i].length <= 20 |
36 |
| - * All A[i] have the same length. |
37 |
| - * All A[i] consist of only lowercase letters. |
38 |
| - * */ |
39 | 8 | public class _893 {
|
40 |
| - |
| 9 | + |
41 | 10 | public static class Solution1 {
|
42 |
| - /**my original solution, a bit lengthy: |
43 |
| - * generate a unique signaure as key for each equivelant group and sum them up*/ |
| 11 | + /** |
| 12 | + * my original solution, a bit lengthy: |
| 13 | + * generate a unique signaure as key for each equivelant group and sum them up |
| 14 | + */ |
44 | 15 | public int numSpecialEquivGroups(String[] A) {
|
45 | 16 | return Arrays.stream(A).map(this::getCommonKey).collect(Collectors.toSet()).size();
|
46 | 17 | }
|
|
0 commit comments