Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions climbing-stairs/Hong-Study.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int climbStairs(int n) {
std::map<int, int> stepMap;
stepMap[1] = 1;
stepMap[2] = 2;

if (n == 1) {
return stepMap[n];
}

for (int i = 3; i <= n; i++) {
stepMap[i] = stepMap[i - 1] + stepMap[i - 2];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 DP 테이블의 가장 최근 n개의 원소만 사용하는 경우에는 O(n) space의 DP 테이블 대신 O(1) space의 변수를 사용해서 공간 복잡도를 한 단계 최적화 할 수 있을 것 같아요~!

}

return stepMap[n];
}
};
34 changes: 34 additions & 0 deletions valid-anagram/Hong-Study.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Time Complexity: O(n log n)
- 분류 정렬에서 O(n log n) 발생

Run time
- 7ms

Memory
- 9.56 MB

최적화쪽으로 수정 추가 필요
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 코드는 정렬 부분에서 O(nlogn) time이지만 이를 카운팅으로 변경한다면 O(n) time으로 최적화 할 수 있을 것 같습니다!

'''
class Solution {
public:
bool isAnagram(string s, string t) {
// 선 길이 체크
if (s.length() != t.length()) {
return false;
}

// 두 배열 정렬(n log n)
std::sort(s.begin(), s.end());
std::sort(t.begin(), t.end());

// 비교하여 다르면 false
for (int i = 0; i < s.length(); i++) {
if (s[i] != t[i]) {
return false;
}
}

return true;
}
};