Skip to content
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

Merged
merged 9 commits into from
Aug 30, 2024
Merged

[kimyoung] WEEK 03 Solutions #389

merged 9 commits into from
Aug 30, 2024

Conversation

kim-young
Copy link
Contributor

@kim-young kim-young commented Aug 27, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@kim-young kim-young self-assigned this Aug 27, 2024
@kim-young kim-young added the js label Aug 27, 2024
@kim-young kim-young requested a review from highballplz August 27, 2024 02:56
@kim-young kim-young marked this pull request as ready for review August 28, 2024 23:28
@kim-young kim-young requested a review from a team as a code owner August 28, 2024 23:28
Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.

위 항목은 체크가 되어 있는데 실제로 되어 있지는 않은 것 같습니다.

Comment on lines +9 to +15
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);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

icoin부터 시작하면 굳이 coin <= i를 체크해줄 필요가 없지 않을까 생각이 들었습니다.

Suggested change
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);
}

Copy link
Contributor Author

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)
Copy link
Contributor

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];
Copy link
Contributor

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 해 주면 가독성이 좀 더 좋아지지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

좋은 리뷰 감사합니다! 이제보니 return statement가 가독성이 많이 떨어지네요. 😂

@kim-young kim-young merged commit 93fe432 into DaleStudy:main Aug 30, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants