-
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
[kimyoung] WEEK 03 Solutions #389
Conversation
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.
- 문제를 모두 푸시면 프로젝트에서 Status를
In Review
로 설정해주세요.
위 항목은 체크가 되어 있는데 실제로 되어 있지는 않은 것 같습니다.
for (let i = 1; i <= amount; i++) { | ||
// only works if coin is less than or equal to the assessing amount | ||
if (coin <= i) { | ||
// min comparison | ||
dp[i] = Math.min(dp[i], dp[i - coin] + 1); | ||
} | ||
} |
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.
i
를 coin
부터 시작하면 굳이 coin <= i
를 체크해줄 필요가 없지 않을까 생각이 들었습니다.
for (let i = 1; i <= amount; i++) { | |
// only works if coin is less than or equal to the assessing amount | |
if (coin <= i) { | |
// min comparison | |
dp[i] = Math.min(dp[i], dp[i - coin] + 1); | |
} | |
} | |
for (let i = coin; i <= amount; i++) { | |
// min comparison | |
dp[i] = Math.min(dp[i], dp[i - coin] + 1); | |
} |
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.
이제보니 이렇게 최적화가 가능했군요. 앞으로는 코드 마무리 후에 최적화 할수 있는 방법도 고민해보도록 하겠습니다!
}; | ||
|
||
// time - O(2^n) backtracking | ||
// space - O(1) |
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.
혹시 curr
배열의 메모리 사용량을 고려하셨나요?
for (let i = 2; i <= n; i++) { | ||
arr[i] = arr[i - 2] + arr[i - 1]; | ||
} | ||
return n === 1 ? 1 : arr[n]; |
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.
안녕하세요 @kim-young 님!
n이 1인지 확인하는 부분은 앞쪽에서 early return 해 주면 가독성이 좀 더 좋아지지 않을까요?
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.
좋은 리뷰 감사합니다! 이제보니 return statement가 가독성이 많이 떨어지네요. 😂
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.