Skip to content

Commit 44c7cdb

Browse files
committed
🎨 Valid Anagram Solution
1 parent 8e56bb8 commit 44c7cdb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

valid-anagram/dalpang81.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
시간복잡도 : O(N)
3+
공간복잡도 : O(1)
4+
*/
5+
6+
class Solution {
7+
public boolean isAnagram(String s, String t) {
8+
if(s.length() != t.length()) return false;
9+
10+
int[] character = new int[26];
11+
12+
for(int i = 0; i < s.length(); i++) {
13+
character[s.charAt(i) - 'a']++;
14+
character[t.charAt(i) - 'a']--;
15+
}
16+
17+
18+
for(int num : character) {
19+
if(num != 0)
20+
return false;
21+
}
22+
23+
return true;
24+
25+
}
26+
}

0 commit comments

Comments
 (0)