forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1657.java
28 lines (25 loc) · 833 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
28
package com.fishercoder.solutions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class _1657 {
public static class Solution1 {
public boolean closeStrings(String word1, String word2) {
int[] counts1 = new int[26];
int[] counts2 = new int[26];
Set<Character> set1 = new HashSet<>();
Set<Character> set2 = new HashSet<>();
for (char c : word1.toCharArray()) {
counts1[c - 'a']++;
set1.add(c);
}
Arrays.sort(counts1);
for (char c : word2.toCharArray()) {
counts2[c - 'a']++;
set2.add(c);
}
Arrays.sort(counts2);
return set1.equals(set2) && Arrays.equals(counts1, counts2);
}
}
}