Skip to content

[rara-record] WEEK 01 solutions #1699

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 4 commits into from
Jul 26, 2025
Merged

Conversation

rara-record
Copy link
Contributor

@rara-record rara-record commented Jul 22, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

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.

수고하셨습니다 ~!

Comment on lines +23 to +26
if num in num_set:
return True
else:
num_set.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.

저는 단순히 set으로 nums를 넣고 길이비교를 생각했었는데 rara님 처럼 풀면 배열 수가 많아질경우 중복된 수가 앞쪽에 있다면 더 빨리 문제가 해결될 것 같습니다!
저희가 코드를 짤때도 실패되는 케이스나 성공하는 케이스에 대해 빠르게 return하는 것을 지향하는 것으로 알고있는데 (무슨 방법론이었나 ..? 이름이 생각이 안나네요..) 좋은 접근인 것 같습니다 ㅎㅎ

Comment on lines +54 to +55
while num + current_length in num_set:
current_length += 1
Copy link
Member

Choose a reason for hiding this comment

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

이 문제를 풀 때 저는 처음에는 이 while문을 보고 n^2가 아닌가 생각했지만 오직 1번만 실행되기에 2N -> N 인 것을 알았습니다. 수고하셨어요!

count_dic[num] = 1

# 빈도수가 큰 순서대로 k개를 반환
return nlargest(k, count_dic, key=count_dic.get)
Copy link
Member

Choose a reason for hiding this comment

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

nlargest() 라는 함수가 있군요 처음알았습니다!

}

1. nums를 한 번 순회하며 각 숫자와 인덱스를 딕셔너리에 저장
2. 다시 nums를 순회하며, target - 현재 숫자가 딕셔너리에 있고 인덱스가 다르면 정답 쌍을 반환
Copy link
Member

Choose a reason for hiding this comment

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

요 부분을 생각해내는게 포인트였던 것 같습니다. target이 되는 2개의 인덱스를 반환해야하므로, 딕셔너리를 사용해서 index정보를 넣고 key로 그 index를 뽑아내는 접근이 좋았습니다.

@rara-record rara-record merged commit b580e8f 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
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.

2 participants