Skip to content

Commit 39cbde1

Browse files
Merge pull request #2102 from CodingTestStudy2/염혜정
[염혜정] Day29
2 parents 361e6b1 + 96514b0 commit 39cbde1

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Comments
 (0)