-
Notifications
You must be signed in to change notification settings - Fork 126
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
[crispy] 3 week solution #392
Conversation
|
||
class Solution { | ||
public: | ||
vector<int> twoSum(vector<int>& nums, int target) { |
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.
투포인터를 사용하셨군요! 시간복잡도를 O(n)
으로 줄일 수 있는 방법도 있는데 나중에 시도해보시면 어떨까요?
coin-change/heozeop.cpp
Outdated
if (dp[i - coin] == MAX_VALUE) { | ||
continue; | ||
} |
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.
언제 이런 경우가 나올 수 있죠?
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.
예를 들어 amoun가 10, coin이 [2, 5] 인 상태를 가정하겠습니다.
i = 3일때, dp[1]은 초기값인 MAX_VALUE를 가지게 됩니다!
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.
아 그렇군요! 예시 감사합니다.
그런데 dp[3]
은 이 체크가 있든 없든 MAX_VALUE
가 될테니, 괜히 코드만 길게 만드는 게 아닌가 생각이 드네요? 🤔
dp[3] = min(1 + dp[2 - 1]), dp[3])
= min(1 + MAX_VALUE, MAX_VALUE)
= MAX_VALUE
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.
넵! 감사합니다!
반영하고 merge하겠습니다!
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.
수고 많으셨습니다!
coin-change/heozeop.cpp
Outdated
if (dp[i - coin] == MAX_VALUE) { | ||
continue; | ||
} |
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.
아 그렇군요! 예시 감사합니다.
그런데 dp[3]
은 이 체크가 있든 없든 MAX_VALUE
가 될테니, 괜히 코드만 길게 만드는 게 아닌가 생각이 드네요? 🤔
dp[3] = min(1 + dp[2 - 1]), dp[3])
= min(1 + MAX_VALUE, MAX_VALUE)
= MAX_VALUE
굳이 필요없는 확인으로 의식적인 이해가 한개 더 필요한 상황 발생
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.
crispy님 안녕하세요 이번에 리뷰를 맞게됐습니다 :)
DP 풀이를 잘하시네요..! 그래서 궁금한점 코멘트로 남겼습니다. 코드 잘봤습니다.👍
이미 merge돼서 approve를 누를수가 없네요. 늦어서 죄송합니다 ㅠ^ㅠ
이번주도 고생하셨습니다!
|
||
dp[0] = dp[1] = 1; | ||
for(int i = 2; i <= n; ++i) { | ||
dp[i] = dp[i - 1] + dp[i - 2]; |
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.
명확한 점화식이네요!
|
||
class Solution { | ||
public: | ||
int coinChange(vector<int>& coins, int amount) { |
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.
dp로 가능하군요..?!
저는 dp로 풀려다가 점화식이 도저히 생각 나지 않아서 bfs로 구현했는데 점화식을 작성하기까지 어떻게 생각하셨나요?
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.
일단 bfs로 먼저 풀고, 점화식을 고민했어요!
결국 최소 개수만 있으면 된다는 점에서 dp로 가능하겠다고 생각했어요!
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.