Skip to content

[Sophia] Week3 Solutions #394

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 2 commits into from
Sep 1, 2024
Merged

[Sophia] Week3 Solutions #394

merged 2 commits into from
Sep 1, 2024

Conversation

seona926
Copy link
Contributor

@seona926 seona926 commented Aug 28, 2024

답안 제출 문제

  • Two Sum
  • Climbing Stairs

체크 리스트

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

@seona926 seona926 marked this pull request as ready for review August 30, 2024 10:00
@seona926 seona926 requested a review from a team as a code owner August 30, 2024 10:00
ways[1] = 1;

for (let i = 2; i <= n; i++) {
ways[i] = ways[i - 1] + ways[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.

점화식을 이용하신 부분이 좋습니다! 👍 조금 더 개선해서 공간 복잡도를 O(1) 으로 줄여보시면 어떨까요?

Copy link
Member

@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.

수고하셨습니다!

Copy link
Contributor

@HC-kang HC-kang left a comment

Choose a reason for hiding this comment

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

@seona926 님 풀이 잘 보았습니다! 한 주 고생많으셨습니다~

let twoSum = function (nums, target) {
let indices = {};

nums.forEach((item, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

16 line 의 조건을 만족하지 않는 경우, 즉, 필요한 경우에만 indices를 추가해준다면 순회 1회를 줄일 수 있지 않을까요?

for (let i = 0; i < nums.length; i++) {
let findNum = target - nums[i];

if (indices[findNum] !== i && findNum.toString() in indices) {
Copy link
Contributor

Choose a reason for hiding this comment

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

findNum.toString() 은 아마 object의 key로 number를 사용하는 부분을 신경 써 주신것 같은데 맞을까요?
이런 목적이 맞으시다면, Map을 사용하는것도 좋지 않을까 싶습니다! 의도적으로 object를 사용하셨다면 무시하셔도 좋습니다!

@SamTheKorean SamTheKorean merged commit 1c502dd into DaleStudy:main Sep 1, 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.

5 participants