Skip to content

Commit f28bb61

Browse files
committed
242. Valid Anagram
1 parent 78dcd51 commit f28bb61

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
3+
1. 아이디어 :
4+
두 문자열 원소의 개수가 같은지 구하기
5+
카운팅 배열을 사용한다.
6+
7+
2. 시간복잡도 : O(N+26) => O(N)
8+
9+
3. 자료구조/알고리즘 : 완전탐색
10+
11+
*/
12+
13+
class Solution {
14+
public boolean isAnagram(String s, String t) {
15+
int len = s.length();
16+
17+
if(s.length() != t.length()) return false;
18+
19+
int[] sCnt = new int[26];
20+
int[] tCnt = new int[26];
21+
22+
for(int i=0; i<len; i++) {
23+
sCnt[s.charAt(i)-'a']++;
24+
tCnt[t.charAt(i)-'a']++;
25+
}
26+
27+
for(int i=0; i<26; i++) {
28+
if(sCnt[i] != tCnt[i]) return false;
29+
}
30+
31+
return true;
32+
}
33+
}

0 commit comments

Comments
 (0)