Skip to content

Conversation

hi-rachel
Copy link
Contributor

@hi-rachel hi-rachel commented Jul 21, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Comment on lines +21 to +22
else:
seen.add(num)
Copy link
Member

Choose a reason for hiding this comment

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

바로 True를 리턴해주니까, else:는 없어도 될 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hyunjung-choi
num을 set에 넣지 않으면 seen 체크를 할 수가 없는데 (숫자를 이미 봤음)
혹시 더 설명해주실 수 있나요?

Copy link
Member

@hyunjung-choi hyunjung-choi Jul 24, 2025

Choose a reason for hiding this comment

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

@hi-rachel 아 저 뜻은 else:없이 바로

for num in nums:
    if num in seen:
        return True
    seen.add(num)
return False

이렇게 해도 될 것 같다는 뜻이었습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hyunjung-choi 굳이 else를 쓰지 않아도 된다는 말씀이셨군요. 그렇네요. 감사합니다!

@@ -31,6 +23,24 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
return [i, j]
Copy link
Member

Choose a reason for hiding this comment

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

O(N)으로 개선하셨네요! 저도 개선해봐야겠어요!👍
근데 이렇게 하면 [1, 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.

@hyunjung-choi @printjin-gmailcom

https://leetcode.com/problems/two-sum/description/

문제에 'You can return the answer in any order.'라고 써있어서 그렇게 냈습니다!

리트코드 풀 때 반환을 요구하는 경우도 봤습니다. 그렇다면 [j, i]로 내야겠네요.

리뷰 감사합니다.

Copy link
Contributor

@printjin-gmailcom printjin-gmailcom left a comment

Choose a reason for hiding this comment

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

첫 주 수고하셨습니다. 남은 두문제도 끝내고 15주차까지 열심히 달려봅시다 :)

TC: O(n)
SC: O(n)
"""

Copy link
Contributor

Choose a reason for hiding this comment

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

16줄의 seen = set() 방식은 하나씩 돌면서 바로 중복을 체크하는 방식이고,
28줄의 len(set(nums)) != len(nums) 방식은 전체 리스트를 한 번에 변환해 길이로 비교하는 방식입니다.
두 가지 방법을 함께 볼 수 있어서 이해하는 데 많은 분들에게 큰 도움이 될 것 같습니다!

@@ -31,6 +23,24 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
return [i, j]
Copy link
Contributor

Choose a reason for hiding this comment

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

리턴할 때 [i, j] 대신 [j, i] 순서가 문제에서 요구하는 경우가 많으니, 문제 조건에 맞게 순서를 한 번 확인해보는 게 좋습니다.
(일반적으로 리트코드에선 이전 인덱스가 먼저 오기에 문제가 안 났지 않을까 싶습니다.)

Comment on lines +21 to +22
else:
seen.add(num)
Copy link
Member

@hyunjung-choi hyunjung-choi Jul 24, 2025

Choose a reason for hiding this comment

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

@hi-rachel 아 저 뜻은 else:없이 바로

for num in nums:
    if num in seen:
        return True
    seen.add(num)
return False

이렇게 해도 될 것 같다는 뜻이었습니다.

@hi-rachel hi-rachel merged commit cecb0bf into DaleStudy:main Jul 26, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from Solving to Completed in 리트코드 스터디 5기 Jul 26, 2025
@yhkee0404
Copy link
Contributor

Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.

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.

4 participants