Skip to content

[doh6077] WEEK 15 solutions#2338

Open
doh6077 wants to merge 6 commits intoDaleStudy:mainfrom
doh6077:main
Open

[doh6077] WEEK 15 solutions#2338
doh6077 wants to merge 6 commits intoDaleStudy:mainfrom
doh6077:main

Conversation

@doh6077
Copy link
Contributor

@doh6077 doh6077 commented Feb 16, 2026

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@doh6077
Copy link
Contributor Author

doh6077 commented Feb 16, 2026

지난주에 참여를 못 해서 이번 주에 누락된 문제들 추가했습니다 :)

@DaleSeo DaleSeo self-requested a review February 18, 2026 00:03
Copy link
Member

@DaleSeo DaleSeo 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 +18 to +19
current_node = queue.popleft()
current_level_nodes.append(current_node.val)
Copy link
Member

Choose a reason for hiding this comment

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

변수명이 좀 길어도 코드를 읽기가 참 편하네요 👍

Comment on lines +15 to +18
if n ==1:
return nums[0]
if n ==2:
return max(nums[0], nums[1])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if n ==1:
return nums[0]
if n ==2:
return max(nums[0], nums[1])
if n == 1:
return nums[0]
if n == 2:
return max(nums[0], nums[1])

return nums[0]
if n ==2:
return max(nums[0], nums[1])
memo = {0:nums[0], 1: max(nums[0], nums[1])}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
memo = {0:nums[0], 1: max(nums[0], nums[1])}
memo = {0: nums[0], 1: max(nums[0], nums[1])}


class Solution:
def rob(self, nums: List[int]) -> int:
# Top Down DP
Copy link
Member

Choose a reason for hiding this comment

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

Top-Down DP로 잘 작성되었지만, 시간이 되신다면 Bottom-Up DP로 메모리 최적화해를 시도해보셔도 좋을 것 같아요.

# Time Complexity O(N)
def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
ans = []
final = [0]
Copy link
Member

Choose a reason for hiding this comment

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

이 곳에 Python의 nonlocal 키워드를 활용해보시기를 추천드립니다. 참고: https://youtu.be/LNWDLXbrZCg

Comment on lines +31 to +41
while q:
curr = q.popleft()

# Only attempt full compare when root values match
if curr.val == subRoot.val and helper(curr, subRoot):
return True

if curr.left:
q.append(curr.left)
if curr.right:
q.append(curr.right)
Copy link
Member

Choose a reason for hiding this comment

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

이 문제는 보통 재귀만으로 해결하는 경우가 많은데, 이렇게 BFS로 각 노드를 순회하며 서브트리 비교를 하는 방법이 신선하네요.

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

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

2 participants

Comments