Skip to content

[Chaewon-Park-STUDY] WEEK 01 Solutions - #2914

Open
Chaewon-Park-STUDY wants to merge 11 commits into
DaleStudy:mainfrom
Chaewon-Park-STUDY:week1
Open

Chaewon-Park-STUDY wants to merge 11 commits into
DaleStudy:mainfrom
Chaewon-Park-STUDY:week1

Conversation

@Chaewon-Park-STUDY

@Chaewon-Park-STUDY Chaewon-Park-STUDY commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Implement twoSum function using a hash map for O(n) time complexity.
@Chaewon-Park-STUDY Chaewon-Park-STUDY moved this from Solving to In Review in 리트코드 스터디 9기 Nov 12, 2026

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

👍 house-robber는 제가 아직 문제를 다 못 풀어서 풀고 난 이후에 추가로 리뷰할게요!
좋은 문제 접근 방법들을 배울 수 있었어요. 감사드립니다.

Comment thread two-sum/Chaewon-Park-STUDY.py Outdated
class Solution:
#시간, 공간 복잡도:O(n)
def twoSum(self, nums: list[int], target: int) -> list[int]:
arr={} #elem를 key로 바로 저장하여 시간복잡도 O(1)

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.

💊 사소한 리뷰입니다. 자료형(dictionary 혹은 map)과 변수의 이름(arr)이 달라서 지금과 같이 복잡하지 않은 코드에서는 괜찮지만 복잡해졌을 때 혼동이 올 수도 있을 것 같아요.

개인적인 의견입니다만, python처럼 동적 타이핑이 가능한 언어에서는 변수명을 통해 어떤 자료형인지 의미를 부여해주는게 좋다고 생각합니다.

@Chaewon-Park-STUDY Chaewon-Park-STUDY Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

소중한 리뷰 감사드립니다! 제가 하나하나 천천히 읽어보고 다시 코멘트 달고 수정하겠습니다:)
@201411108 한동님께서도 파이썬으로 작성하셨는데 제 코드와 비교대조하면서 추가리뷰도 진행해보겠습니다

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

중요한 지적 감사합니다!

제가 아닌 타인이 해석 가능한 코드가 좋은 코드라고 생각이되는데, 이렇게 변수명부터 고쳐 나가야 나중에 긴 코드를 짤 때도 명확해질 것 같네요.
arr에서 num_index로 수정하였습니다~

# count로 하면 전체를 다 훑기 때문에 O(n^2)
# dic 사용하여 공간 복잡도: O(n)
for elem in nums:
frequent[elem] = frequent.get(elem, 0) + 1 # dic에 기존 key가 없다면 value 1 저장

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.

💬 defaultdict(int)를 쓰면 존재하지 않는 key에 접근하더라도 에러를 내주지 않고 기본값으로 key와 value를 자동으로 생성해주는 기능이 있습니다!
key 없을 때 처리를 따로 하지 않아도 되는 편리함을 줄 수 있어서 공유드립니다.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

항상 get을 써왔었는데 defaultdict(int) 자주 활용해야겠습니다! 감사합니다

Comment on lines +17 to +19
if len(output)==k:
break
return output

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.

💬 len(output) == k일 때가 종료 조건이기 때문에 break 대신 return을 적어줘도 동일하게 동작합니다.
선호하는 코딩 스타일에 따라 다르겠지만 문맥 상 종료 조건일 때 함수를 종료하는 것이 맞다고 생각하여 의견 남겨봅니다.

@Chaewon-Park-STUDY Chaewon-Park-STUDY Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

return output으로 바로 고치는 방향이 명확할 듯 하네요👍

def longestConsecutive(self, nums: list[int]) -> int:
if not nums:
return 0
nums = sorted(set(nums)) # 처음에는 nums.sort()로 풀었지만

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.

❗ 저도 처음에는 sorted로 원소들을 정렬한 다음 푸는 방법을 사용했었는데요. 개선할 수 있는 방법이 있더라고요.
지금 풀이는 연속 수열이 끝나는 길이를 작성하는 방식으로 풀이를 진행하셨는데, 연속 수열이 시작하는 지점을 이용하면 시간 복잡도를 줄여볼 수 있습니다.

지금 풀이도 "오, 이렇게 생각할 수 있구나."라는 생각이 들었던 좋은 풀이라고 생각합니다!

Comment thread house-robber/Chaewon-Park-STUDY.py Outdated
def rob(self, nums: list[int]) -> int:
#시간, 공간 복잡도: O(n)
if len(nums)==1:
return sum(nums)

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.

💊 길이가 1이면 배열의 원소만 반환해줘도 좋을 것 같습니다.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nums[0]으로 고치겠습니다~

Comment on lines +9 to +11
for i in range(2,len(nums)):
house3 = dp[i-3] if i >= 3 else 0 #i=2일 경우에는 i-3이 존재하지 않기에 따로 처리
dp[i] += max(dp[i-2], house3) #인접한 집은 방문 불가

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라는 배열에 index에 해당하는 집을 털었을 때 벌 수 있는 가장 큰 수익을 저장하는 용도로 사용하셨군요.
좋은 풀이 감사합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants