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 4db1f8b commit b23ba20Copy full SHA for b23ba20
1 file changed
valid-anagram/Hyeri1ee.java
@@ -0,0 +1,34 @@
1
+import java.util.*;
2
+
3
+class Solution {
4
+ public boolean isAnagram(String s, String t) {
5
+ if (s.length() != t.length()) return false;
6
7
+ //s를 hashmap에 저장하고, t에서 하나씩 없애기
8
+ HashMap<Character, Integer> maps = new HashMap<>();
9
10
+ for(int i =0 ; i < s.length(); i++){
11
+ char c = s.charAt(i);
12
13
+ if (maps.containsKey(c)) maps.put(c, maps.get(c)+1);
14
+ else maps.put(c, 1);
15
16
+ }
17
18
+ for(int i = 0; i< t.length() ;i++){
19
+ char c = t.charAt(i);
20
+ if (maps.containsKey(c)){
21
+ if (maps.get(c) > 1) maps.put(c, maps.get(c) - 1);
22
+ else maps.remove(c);
23
24
25
26
27
+ if (maps.size() == 0) return true;
28
29
+ return false;
30
31
32
33
34
+}
0 commit comments