We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5487b35 commit bdf91d1Copy full SHA for bdf91d1
valid-anagram/donghyeon95.java
@@ -0,0 +1,27 @@
1
+import java.util.HashMap;
2
+import java.util.HashSet;
3
+import java.util.Map;
4
+
5
+class Solution {
6
+ public boolean isAnagram(String s, String t) {
7
+ boolean result = false;
8
9
+ char[] chars = s.toCharArray();
10
+ Map<Character, Integer> counter = new HashMap<>();
11
+ for (char c: chars) {
12
+ counter.put(c, counter.getOrDefault(c, 0)+1);
13
+ }
14
15
+ char[] tChars = t.toCharArray();
16
+ for (char c: tChars) {
17
+ if (!counter.containsKey(c)) return false;
18
+ counter.put(c, counter.get(c)-1);
19
20
+ if (counter.get(c) == 0)
21
+ counter.remove(c);
22
23
24
+ return counter.isEmpty();
25
26
+}
27
0 commit comments