Skip to content

[jeongwoo903] Week 02 solutions #1230

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 6 commits into from
Apr 12, 2025
Merged

Conversation

jeongwoo903
Copy link
Member

@jeongwoo903 jeongwoo903 commented Apr 7, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Sorry, something went wrong.

return result;
}, { products: lefts, rights: 1 }
).products;
};
Copy link
Member

Choose a reason for hiding this comment

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

대부분의 풀이 아이디어가 비슷해서 reduce는 생각못했는데, 이런 접근법도 있군요!
reduce와 reduceRight를 활용해서 코드를 간결하게 작성한 점이 인상적입니다.
다만 처음 보는 사람이 이해하기에는 약간 복잡할 수 있겠다는 생각도 들었습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

제가 가끔 함수형으로 짜본다고 다음과 같이 코드를 짰는데 조금 가독성이 나쁜 코드인 것 같다고 생각하긴 했습니다..ㅎㅎ
좋은 의견 감사합니다!

}

return dp[n-1]
};
Copy link
Member

Choose a reason for hiding this comment

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

코드 자체는 깔끔하고 효율적으로 작성되었네요 👍
DP 배열을 구성하는 스타일에는 여러 가지가 있고
현재 코드는 dp[0]이 1번째 계단, dp[1]이 2번째 계단을 의미하는 방식으로 작성되었습니다.

또 다른 스타일로는 인덱스와 계단 번호를 일치시키는 방법도 많이 사용되는거같아 제안사항은 아니지만 공유드립니다.
:

var climbStairs = function(n) {
  const dp = [1, 1]; // dp[0]은 0번째(시작점), dp[1]은 1번째 계단
  
  for (let i = 2; i <= n; i++) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  
  return dp[n];
};

이런 방식으로 하면 "dp[i]는 i번째 계단에 도달하는 방법의 수"라고 직관적으로 이해할 수 있어서 코드 가독성 면에서 장점이 있습니다. 물론 이건 단지 스타일의 차이일 뿐이고, 어느 쪽이든 문제 해결에는 차이가 없습니다.

두 방식 모두 많이 사용되는 패턴인거같아 공유드립니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

로직에는 차이가 없어도 다음과 같이 바꿈으로써 설명과 가독성이 나아지는 것 같네요 ㅎㅎ
알려주셔서 감사합니다!

@jeongwoo903 jeongwoo903 moved this from Solving to In Review in 리트코드 스터디 4기 Apr 11, 2025
@hsskey
Copy link
Member

hsskey commented Apr 12, 2025

@jeongwoo903 확인완료하였습니다

@jeongwoo903 jeongwoo903 merged commit 7017c79 into DaleStudy:main Apr 12, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 Apr 12, 2025
@jeongwoo903 jeongwoo903 changed the title [jeongwoo903] Week 02 Solutions [jeongwoo903] Week 02 solutions Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants