2 parents 361e6b1 + 96514b0 commit 39cbde1Copy full SHA for 39cbde1
1 file changed
leetcode3/염혜정/242. Valid Anagram.java
@@ -0,0 +1,20 @@
1
+// o(n)
2
+
3
+class Solution {
4
+ public boolean isAnagram(String s, String t) {
5
+ if (s.length() != t.length()) return false;
6
7
+ int[] cnt = new int[26];
8
+ for (int i = 0; i<s.length(); i++) {
9
+ int ord = (int) s.charAt(i) - 97;
10
+ cnt[ord]++;
11
+ }
12
13
+ for (int i = 0; i<t.length(); i++) {
14
+ int ord = (int) t.charAt(i) - 97;
15
+ if (cnt[ord] == 0) return false;
16
+ cnt[ord]--;
17
18
+ return true;
19
20
+}
0 commit comments