Skip to content

[yuseok89] WEEK 14 Solutions - #2867

Merged
parkhojeong merged 3 commits into
DaleStudy:mainfrom
yuseok89:main
Sep 27, 2026
Merged

parkhojeong merged 3 commits into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

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.

🏷️ 알고리즘 패턴 분석

binary-tree-level-order-traversal/yuseok89.py
# TC: O(N)
# SC: O(N)
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def levelOrder(self, root: TreeNode | None) -> list[list[int]]:

        ret = []

        def preOrder(root: TreeNode | None, height: int):
            if len(ret) == height:
                ret.append([])

            ret[height].append(root.val)

            if root.left:
                preOrder(root.left, height + 1)
            if root.right:
                preOrder(root.right, height + 1)

        if root:
            preOrder(root, 0)

        return ret
  • 패턴: Depth-First Search, Binary Search, Monotonic Stack, Breadth-First Search, Hash Map / Hash Set, Dynamic Programming, Two Pointers, Sliding Window, Fast & Slow Pointers, Backtracking, Divide and Conquer, Union Find, Trie, Bit Manipulation, Heap / Priority Queue, Greedy
  • 설명: 주어진 코드는 재귀를 이용한 트리의 각 레벨에 값을 모으는 방식으로 구현되었으며, 실제로 깊이 우선 탐색(DFS)으로 각 높이에 따라 결과를 분리하여 저장합니다. 원래 의도는 레벨 순서 순회(BFS)이지만 재귀 구조로 구현되어 DFS 패턴으로 분류됩니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n) ✅
Space O(N) O(n) ✅

피드백: 재귀를 통해 트리를 순회하고 각 높이에 따라 리스트를 확장하며 값을 추가한다. 레벨 순서를 얻으려면 큐를 이용한 BFS가 일반적이지만 현재 구현은 프리오더 순회로 동작한다.

개선 제안: 현재 구현이 적절해 보입니다.

Comment thread counting-bits/yuseok89.py

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.

🏷️ 알고리즘 패턴 분석

counting-bits/yuseok89.py
# TC: O(N)
# SC: O(N)
class Solution:
    def countBits(self, n: int) -> list[int]:
        ans = []

        upper = 1
        ans.append(0)

        for idx in range(1, n + 1):
            ans.append(ans[idx - upper] + 1)

            if idx == upper:
                upper *= 2

        return ans
  • 패턴: Dynamic Programming, Two Pointers, Hash Map / Hash Set
  • 설명: 주어진 코드는 이진수에서 각 수의 1의 개수를 구하는 DP 방식의 점화식(전개식)을 활용합니다. 이전 값들을 이용해 현재 값을 계산하고, 상위 블록 경계에서 값을 갱신하는 형태로 최적화됩니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n) ✅
Space O(N) O(n) ✅

피드백: 동적 계획으로 각 수의 비트를 빠르게 계산한다. 상향식으로 이전 값을 활용해 O(n) 시간에 n개의 결과를 얻는다.

개선 제안: 현재 구현이 적절해 보입니다.

@dalestudy

dalestudy Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📊 yuseok89 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
binary-tree-level-order-traversal Medium ⚠️ 유형 불일치
counting-bits Easy ✅ 의도한 유형
house-robber-ii Medium ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 61 / 75개
  • 이번 주 유형 일치율: 67% (3문제 중 2문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Array ■■■■■■■ 10 / 10 (Medium 7, Easy 3)
Linked List ■■■■■■■ 6 / 6 (Easy 3, Hard 1, Medium 2)
Heap ■■■■■■■ 3 / 3 (Hard 2, Medium 1)
Dynamic Programming ■■■■■■□ 10 / 11 (Easy 1, Medium 9)
Binary ■■■■■■□ 4 / 5 (Easy 3, Medium 1)
String ■■■■■■□ 8 / 10 (Medium 4, Hard 1, Easy 3)
Matrix ■■■■■□□ 3 / 4 (Medium 3)
Tree ■■■■■□□ 10 / 14 (Hard 2, Medium 5, Easy 3)
Graph ■■■■□□□ 5 / 8 (Medium 5)
Interval ■■■■□□□ 3 / 5 (Medium 3)

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,016 154 1,170 $0.000112

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-ii/yuseok89.py
# TC: O(N)
# SC: O(1)
class Solution:
    def rob(self, nums: list[int]) -> int:

        n = len(nums)

        def calc(nums, s, e):
            rob, skip = 0, 0
            for idx in range(s, e):
                rob, skip = skip + nums[idx], max(rob, skip)

            return max(rob, skip)

        if n == 1:
            return nums[0]

        return max(calc(nums, 0, n - 1), calc(nums, 1, n))
  • 패턴: Dynamic Programming, Greedy
  • 설명: 배열을 순차적으로 순회하며 현재까지의 최대 이익을 rob/skip로 관리하는 DP 형태이며, 원형 배열의 첫/마지막 요소 중 무엇을 선택할지 두 경우로 나눠 최댓값을 비교한다. 이는 House Robber II의 최적해를 구하는 전형적 DP 패턴과 분할로 최소한의 중복계산을 사용한 결정 로직을 포함한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n) ✅
Space O(1) O(1) ✅

피드백: 두 구간으로 나누어 DP를 수행하고, 원소의 개수에 따라 첫 원소 포함/미포함 두 경우를 비교한다. 공간은 상수로 유지된다.

개선 제안: 현재 구현이 적절해 보입니다.

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

좋아요!

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.

엄청 깔끔하게 잘 해결하셨네요!
정말 아주 억지로 트집잡자면 재귀가 트리의 높이만큼 스택이 쌓이니까 Iterative하게 시도해 보는거를 한번 해보시는것도 좋다는 정도려나요?
깔끔한 코드 잘 보고 갑니다!

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.

진짜 회원님 코드 볼때마다 느끼는거지만 Leetcode Study 처음 오셨을때랑 지금이랑 차이가 어마어마하신것 같아서 대단한거 같아요
고생이 많으십니다!

Comment thread counting-bits/yuseok89.py

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.

상당히 깔끔하게 잘 해결하셨네요!

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.

오 문제를 함수로 일반화 하신다음에 따로 두가지 경우로 구현하셨네요
그 덕분에 코드가 상당히 가독성이 좋아지는것 같아요!

@parkhojeong
parkhojeong merged commit f8ac42b into DaleStudy:main Sep 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants