-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path242.java
More file actions
32 lines (32 loc) · 855 Bytes
/
242.java
File metadata and controls
32 lines (32 loc) · 855 Bytes
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
class Solution {
public boolean isAnagram(String s, String t) {
HashMap<Character, Integer> hs = new HashMap<>();
for (char ch : s.toCharArray()) {
if (hs.containsKey(ch) == false) {
hs.put(ch, 1);
} else {
hs.put(ch, hs.get(ch) + 1);
}
}
for (char ch : t.toCharArray()) {
if (hs.containsKey(ch) == true) {
hs.put(ch, hs.get(ch) - 1);
} else {
return false;
}
}
Boolean b = false;
for (Integer v : hs.values()) {
if (v == 0) {
b = true;
} else {
b = false;
break;
}
}
if (b == true) {
return true;
} else
return false;
}
}