Skip to content

[yhkee0404] WEEK 02 solutions #1757

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 5 commits into from
Aug 2, 2025
Merged

[yhkee0404] WEEK 02 solutions #1757

merged 5 commits into from
Aug 2, 2025

Conversation

yhkee0404
Copy link
Contributor

@yhkee0404 yhkee0404 commented Jul 31, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@yhkee0404 yhkee0404 changed the title [yhkee0404] WEEK 01 solutions [yhkee0404] WEEK 02 solutions Jul 31, 2025
@yhkee0404 yhkee0404 moved this from Solving to In Review in 리트코드 스터디 5기 Jul 31, 2025
@rivkode rivkode self-requested a review July 31, 2025 22:20
Copy link
Member

@rivkode rivkode left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 ~!

break
}
if (u == - nums[k]) {
ans.add(listOf(nums[i], nums[j], nums[k]))
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 궁금해서 그러는데 이렇게 list로만 add를 해주면 중복이 발생하지 않을까요 ? 만약 제거가 된다면 어디서 처리가 될까요 ?

Copy link
Contributor Author

@yhkee0404 yhkee0404 Aug 1, 2025

Choose a reason for hiding this comment

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

안녕하세요, continue를 2군데에서 사용했는데 동일한 원소가 연속적으로 발견되는 경우 Dynamic Programming의 Memoization과 같은 원리로 계산을 건너뛰었어요. 이러한 Tuple의 중복 검사를 위해서는 단순히 Set 자료구조를 사용할 수도 있습니다. 그런데 지금처럼 정렬된 상황에는 Two Pointers를 이용할 수 있어요. 뿐만 아니라 Tuple 내 Index를 탐색하는 순서에 따라 Short-Circuit을 적용하면 추가적인 시간 절약도 기대할 수 있어요. 모든 Tuple 간 중복을 검사하기 위해 중복을 허용하고 생성하는 풀이에 비해 적어도 중복 Tuple 개수 이상의 Tuple 생성 시간 절약 효과를 얻을 수 있습니다.

Copy link
Member

Choose a reason for hiding this comment

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

아 설명을 듣고 다시 보니 투포인터를 사용하셨군요! 이제 이해했습니다. 정렬된 상황이라 이전과 같은 숫자에 대해서 continue 로 중복을 제거해주니 중복 처리는 되었고 투포인터로 조건에 맞는 2개의 숫자에 대해서 빠르게 탐색이 되겠네요. 친절한 설명 감사합니다

Copy link
Member

Choose a reason for hiding this comment

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

아! 그리고 short circuit이 이거였군요! 제가 저번 week1 에서 이 용어를 몰라서 헤멨는데 이거였습니다 ㅎㅎㅎ 여기서 알게된게 신기하네요 ㅋㅋㅋ

#1699 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

맞네요! Pruning 등 더 생각 나는 용어를 여기 정리해 봤습니다: #1699 (comment)
예를 들어 저는 순차 탐색의 성질만 이용했으니 Memoization이나 Caching이라고 하기는 어렵겠네요.

}
a = 1;
for i in 0..nums.len() {
ans[i] = a * (if i == nums.len() - 1 {1} else {ans[i + 1]});
Copy link
Member

Choose a reason for hiding this comment

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

저는 0의 케이스에 대해서 0이 존재하는 개수를 기준으로 3부분으로 나누어서 구별하였는데 이 코드에서는 어떻게 0의 예외케이스에 대해서 구분을 하셨을까요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

안녕하세요, 저는 0의 예외케이스를 고려하지 않아서 이해가 어려웠는데 그래도 됐던 이유를 @rivkode 님의 코드를 통해 이해하고 여기 설명해 봤습니다: #1758 (comment)

Copy link
Member

@rivkode rivkode Aug 1, 2025

Choose a reason for hiding this comment

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

저의 읽기 실력을 더 키워야겠군요 ㅋㅋㅋ 친절한 설명 감사합니다!

전체적으로 코드가 깔끔한 것 같습니다. 앞으로 리뷰가 아니더라도 시간이 되면 종종 @yhkee0404 님의 코드를 살펴봐야겠습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Week 1에서 저도 사실 #237 문제 풀 때 O(nlogn)보다 빨라야 한다는 조건을 놓쳤답니다.. 좋게 봐주셔서 감사합니다!

@yhkee0404 yhkee0404 mentioned this pull request Aug 1, 2025
10 tasks
@yhkee0404 yhkee0404 merged commit 0b88304 into DaleStudy:main Aug 2, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 5기 Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants