Skip to content

Commit 932b4f5

Browse files
committed
[week2] Valid Anagramp Sold
1 parent 6bdb8a9 commit 932b4f5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

valid-anagram/Hong-Study.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Time Complexity: O(n log n)
3+
- 분류 정렬에서 O(n log n) 발생
4+
5+
Run time
6+
- 7ms
7+
8+
Memory
9+
- 9.56 MB
10+
11+
최적화쪽으로 수정 추가 필요
12+
'''
13+
class Solution {
14+
public:
15+
bool isAnagram(string s, string t) {
16+
// 선 길이 체크
17+
if (s.length() != t.length()) {
18+
return false;
19+
}
20+
21+
// 두 배열 정렬(n log n)
22+
std::sort(s.begin(), s.end());
23+
std::sort(t.begin(), t.end());
24+
25+
// 비교하여 다르면 false
26+
for (int i = 0; i < s.length(); i++) {
27+
if (s[i] != t[i]) {
28+
return false;
29+
}
30+
}
31+
32+
return true;
33+
}
34+
};

0 commit comments

Comments
 (0)