-
-
Notifications
You must be signed in to change notification settings - Fork 195
[oyeong011] week2 #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[oyeong011] week2 #730
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9871f0b
valid-anagram sol
oyeong011 00da909
Merge remote-tracking branch 'origin/main'
oyeong011 bddaee7
valid-anagram sol
oyeong011 da5385c
valid-anagram sol
oyeong011 626d390
valid-anagram sol 줄바꿈
oyeong011 bfa66f6
Climbing stairs sol
oyeong011 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Solution { | ||
public: | ||
int climbStairs(int n) { | ||
if(n == 0 || n == 1){ | ||
return 1; | ||
} | ||
vector<int> dp(n + 1); | ||
dp[0] = dp[1] = 1; | ||
for(int i = 2; i <= n; i++){ | ||
dp[i] = dp[i-1] + dp[i - 2]; | ||
} | ||
return dp[n]; | ||
} | ||
}; | ||
|
||
// dp 문제로 배열을 생성해준다 | ||
// 계단 방식 | ||
// 1 1개 | ||
// 1 + 1, 2 2개 | ||
// 1 + 1 + 1, 2 + 1, 1 + 2 3개 | ||
// 1 + 1 + 1 + 1, 1 + 1 + 2, 1 + 2 + 1, 2 + 1 + 1, 2 + 2 ---> 5개 | ||
// 즉 피보나찌 수열의 형태를 띈다 왜냐면 2칸을 뛰기 때문에 한칸전에 1을 더하고 두칸 전에 경우의 수에 2를 더해주면 되기때문 | ||
// 즉 f(n) = f(n - 1) + f(n - 2) | ||
// 만약 계단 방식이 3칸까지이면 즉 f(n) = f(n - 1) + f(n - 2) + f(n - 3) | ||
// 시간복잡도는 n만큼 순회하여 O(n) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||||||
class Solution { | ||||||||||
public: | ||||||||||
bool isAnagram(string s, string t) { | ||||||||||
unordered_map<char, int> ss, tt; | ||||||||||
if(s.length() != t.length())return false; | ||||||||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
s와 t의 길이가 다르면 unordered_map을 할당할 필요도 없으니까 5번 줄이 더 위에 있는게 나을 것 같아요 |
||||||||||
for(auto i : s) ss[i]++; | ||||||||||
for(auto i : t) tt[i]++; | ||||||||||
return ss == tt; | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
// 문자열 비교 unordered_map은 해쉬 형태이므로 O(1) | ||||||||||
// 각 문자 루프 O(n) | ||||||||||
// 마지막 문자 비교 해시멥 알파벳은 26개 이므로 O(n) | ||||||||||
// 따라서 O(n) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔한 풀이에 피보나치 수열인 것까지 잘 캐치하신 것 같습니다 ㅎㅎ
누락된 공간 복잡도 분석 추가하시면 더 좋을 것 같고, 분석하시는 동시에 공간 복잡도를 최적화할 수 있을지 여부에 대해서 한 번 더 생각해보시면 좋을 것 같아요