Skip to content

Commit 5b24489

Browse files
committed
feat: week02 valid-anagram
1 parent cfca352 commit 5b24489

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

valid-anagram/std-freejia.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)