- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1657.java
27 lines (25 loc) · 847 Bytes
/
_1657.java
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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.Arrays;
importjava.util.HashSet;
importjava.util.Set;
publicclass_1657 {
publicstaticclassSolution1 {
publicbooleancloseStrings(Stringword1, Stringword2) {
int[] counts1 = newint[26];
int[] counts2 = newint[26];
Set<Character> set1 = newHashSet<>();
Set<Character> set2 = newHashSet<>();
for (charc : word1.toCharArray()) {
counts1[c - 'a']++;
set1.add(c);
}
Arrays.sort(counts1);
for (charc : word2.toCharArray()) {
counts2[c - 'a']++;
set2.add(c);
}
Arrays.sort(counts2);
returnset1.equals(set2) && Arrays.equals(counts1, counts2);
}
}
}