Skip to content

[ehlung] WEEK 01 Solutions - #2924

Merged
dalestudy[bot] merged 5 commits into
DaleStudy:mainfrom
ehlung:week-01
Nov 15, 2026
Merged

dalestudy[bot] merged 5 commits into
DaleStudy:mainfrom
ehlung:week-01

Conversation

@ehlung

@ehlung ehlung commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

🤖 AI 리뷰(알고리즘 패턴, 시간/공간 복잡도, 학습 현황) 결과는 Checks 탭에서 볼 수 있어요.

@dalestudy dalestudy Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

현재 주차가 종료되어 자동으로 승인되었습니다. PR을 병합해주세요!

@dalestudy
dalestudy Bot merged commit 6a357b7 into DaleStudy:main Nov 15, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 9기 Nov 15, 2026
@hyedall
hyedall self-requested a review November 15, 2026 05:07

@hyedall hyedall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

풀이마다 시간, 공간 복잡도를 자세히 정리해주셔서 이해하기 편했습니다.
전반적으로 복잡도를 충분히 고민하고 효율적으로 구현해주셔서 많이 배워갑니다 👍

Comment thread two-sum/ehlung.py
Comment on lines +2 to +16
n = nums의 길이
시간 복잡도: O(n) - 각 숫자를 한 번씩 확인 (딕셔너리 조회/저장은 O(1))
공간 복잡도: O(n) - 숫자와 인덱스를 담는 딕셔너리
"""


class Solution:
def twoSum(self, nums: list[int], target: int) -> list[int]:
index_of = {}
for i, num in enumerate(nums):
need = target - num
if need in index_of:
return [index_of[need], i]
index_of[num] = i
return []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

한 번의 순회로 필요한 값을 조회하고, 현재 숫자 인덱스까지 저장해 O(n)으로 효율적으로 푸셔서 배워갑니다! 😆

Comment on lines +10 to +15
count = {}
for num in nums:
count[num] = count.get(num, 0) + 1

sorted_nums = sorted(count, key=lambda num: count[num], reverse=True)
return sorted_nums[:k]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

저는 Counter.most_common(k)를 사용해서 비슷한 방식으로 풀었는데, collections 라이브러리 없이 잘 구현해주신 것 같습니다 !
알고달레 풀이를 확인해보니 배열의 인덱스로 빈도를 저장하는 방식으로 풀면 문제 Follow-up 요구사항을 만족하는 O(n)로 풀 수 있어서 함께 참고해보면 좋을 것 같습니다👍

Comment thread house-robber/ehlung.py
Comment on lines +9 to +14
def rob(self, nums: list[int]) -> int:
# prev2: 두 집 전까지의 최대 금액, prev1: 바로 전 집까지의 최대 금액
prev2, prev1 = 0, 0
for money in nums:
prev2, prev1 = prev1, max(prev2 + money, prev1)
return prev1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DP 배열 없이 변수 2개만 사용해 공간 복잡도를 최적화해서 잘 풀어주신 것 같습니다👍

Comment on lines +10 to +15
seen = set()
for num in nums:
if num in seen:
return True
seen.add(num)
return False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

순회 중 중복을 발견하는 즉시 반환해서 불필요한 탐색을 줄인 점이 좋은 것 같습니다 😆

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