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

[crispy] 3 week solution #392

Merged
merged 9 commits into from
Aug 29, 2024
Merged

[crispy] 3 week solution #392

merged 9 commits into from
Aug 29, 2024

Conversation

heozeop
Copy link
Contributor

@heozeop heozeop commented Aug 27, 2024

답안 제출 문제

체크 리스트

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

@heozeop heozeop added the c++ label Aug 27, 2024
@heozeop heozeop self-assigned this Aug 27, 2024
@heozeop heozeop requested a review from a team as a code owner August 27, 2024 11:18
@heozeop heozeop requested a review from Sunjae95 August 27, 2024 11:19

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
Copy link
Contributor

Choose a reason for hiding this comment

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

투포인터를 사용하셨군요! 시간복잡도를 O(n) 으로 줄일 수 있는 방법도 있는데 나중에 시도해보시면 어떨까요?

combination-sum/heozeop.cpp Outdated Show resolved Hide resolved
Comment on lines 23 to 25
if (dp[i - coin] == MAX_VALUE) {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

언제 이런 경우가 나올 수 있죠?

Copy link
Contributor Author

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를 가지게 됩니다!

Copy link
Contributor

@DaleSeo DaleSeo Aug 29, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵! 감사합니다!
반영하고 merge하겠습니다!

@heozeop heozeop requested a review from DaleSeo August 29, 2024 01:30
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.

수고 많으셨습니다!

Comment on lines 23 to 25
if (dp[i - coin] == MAX_VALUE) {
continue;
}
Copy link
Contributor

@DaleSeo DaleSeo Aug 29, 2024

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

굳이 필요없는 확인으로 의식적인 이해가 한개 더 필요한 상황 발생
@heozeop heozeop merged commit 4480634 into DaleStudy:main Aug 29, 2024
1 check passed
Copy link
Contributor

@Sunjae95 Sunjae95 left a 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];
Copy link
Contributor

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

Choose a reason for hiding this comment

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

dp로 가능하군요..?!
저는 dp로 풀려다가 점화식이 도저히 생각 나지 않아서 bfs로 구현했는데 점화식을 작성하기까지 어떻게 생각하셨나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

일단 bfs로 먼저 풀고, 점화식을 고민했어요!
결국 최소 개수만 있으면 된다는 점에서 dp로 가능하겠다고 생각했어요!

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.

4 participants