-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnagrams
34 lines (28 loc) · 943 Bytes
/
Anagrams
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
static boolean isAnagram(String a, String b) {
if (a.length() != b.length()) {
return false;
}
String aLow = a.toLowerCase();
String bLow = b.toLowerCase();
java.util.HashMap<Character, Integer> temp = new java.util.HashMap<Character, Integer>();
for(int i = 0; i < a.length(); i++){
char cA = aLow.charAt(i);
char cB = bLow.charAt(i);
if (temp.get(cA) == null) {
temp.put(cA, 1);
}else{
temp.put(cA, temp.get(cA)+1);
}
if (temp.get(cB) == null) {
temp.put(cB, 1);
} else{
temp.put(cB, temp.get(cB)+1);
}
}
for(int i : temp.values()){
if (i %2 != 0) {
return false;
}
}
return true;
}