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 cfca352 commit 5b24489Copy full SHA for 5b24489
valid-anagram/std-freejia.java
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ public boolean isAnagram(String s, String t) {
3
+ if (s.length() != t.length()) return false;
4
+
5
+ Map<Character, Integer> mapS = new HashMap<>();
6
+ Map<Character, Integer> mapT = new HashMap<>();
7
8
+ for (int i = 0; i < s.length(); i++) {
9
+ mapS.put(s.charAt(i), mapS.getOrDefault(s.charAt(i), 0) + 1);
10
+ mapT.put(t.charAt(i), mapT.getOrDefault(t.charAt(i), 0) + 1);
11
+ }
12
+ return mapS.equals(mapT);
13
14
+}
0 commit comments