Skip to content

Commit 2e92f09

Browse files
authored
Merge pull request #2059 from Hong-Study/main
[Hong-Study] WEEK 02 Solutions
2 parents 4a3c5fb + bb02823 commit 2e92f09

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

climbing-stairs/Hong-Study.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int climbStairs(int n) {
4+
std::map<int, int> stepMap;
5+
stepMap[1] = 1;
6+
stepMap[2] = 2;
7+
8+
if (n == 1) {
9+
return stepMap[n];
10+
}
11+
12+
for (int i = 3; i <= n; i++) {
13+
stepMap[i] = stepMap[i - 1] + stepMap[i - 2];
14+
}
15+
16+
return stepMap[n];
17+
}
18+
};

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)