Skip to content

[dahyeong-yun] WEEK 10 Solutions - #2840

Merged
dahyeong-yun merged 2 commits into
DaleStudy:mainfrom
dahyeong-yun:week-10
Aug 29, 2026
Merged

[dahyeong-yun] WEEK 10 Solutions#2840
dahyeong-yun merged 2 commits into
DaleStudy:mainfrom
dahyeong-yun:week-10

Conversation

@dahyeong-yun

@dahyeong-yun dahyeong-yun commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn 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.

🏷️ 알고리즘 패턴 분석

invert-binary-tree/dahyeong-yun.java
/**
 * TC : O(n)
 *   - 모든 노드를 방문해야 함
 * SC : O(n)
 *   - 콜 스택이 n까지 쌓일 수 있음
 */
class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null) return root;

        // 다음에 다음이 있는 경우만 스왑해서 리턴
        if(root.left != null || root.right != null) {
            TreeNode temp = invertTree(root.left);
            root.left = invertTree(root.right);
            root.right = temp;
        }

        return root;
    }
}
  • 패턴: Depth-First Search, Backtracking
  • 설명: 트리의 모든 노드를 재귀적으로 방문하며 좌우를 교환하는 방식으로 트리를 뒤집는 DFS 구조이며, 각 노드의 처리 후 재귀 호출로 상태를 역전시키는 백트래킹 특성을 보인다.

📊 시간/공간 복잡도 분석

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

피드백: 모든 노드를 방문하며, 최악의 경우 호출 스택이 트리 깊이만큼 쌓일 수 있다.

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

@github-actions github-actions Bot added the java label Aug 29, 2026
@dalestudy

dalestudy Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

📊 dahyeong-yun 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
invert-binary-tree Easy ✅ 의도한 유형
search-in-rotated-sorted-array Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 754 74 828 $0.000067

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.

🏷️ 알고리즘 패턴 분석

search-in-rotated-sorted-array/dahyeong-yun.java
/**
 * TC : O(log n)
 *   - 이진 탐색을 수행하기 때문에 log n
 * SC : O(1)
 *   - 별도 유의미한 공간 할당이 없음
 */
class Solution {
    public int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;

        while (left <= right) {
            int mid = (left + right) / 2; 

            if(nums[mid] == target) {
                return mid;
            }

            if (nums[left] <= nums[mid]) {
                if(nums[left] <= target && target <= nums[mid])
                    right = mid;
                else
                    left = mid + 1;
            } else {
                if (nums[mid] <= target && target <= nums[right])
                    left = mid;
                else
                    right = mid - 1;
            }
        }
        return -1;
    }
}
  • 패턴: Binary Search, Monotonic Stack
  • 설명: 배열이 회전되었더라도 이진 탐색으로 중간값과 경계 비교를 통해 타겟 위치를 탐색하므로 Binary Search 패턴에 속합니다. 회전으로 인한 구간 단순화는 맥락상 이진 탐색의 유효성을 유지하는_monotonic 부분(부분 배열의 정렬성 유지)으로 해석할 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 회전된 배열에서도 이진 탐색의 성질을 유지하며 인덱스 범위를 조정한다.

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

@Yiseull
Yiseull self-requested a review August 29, 2026 06:43

@Yiseull Yiseull 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 on lines +12 to +16
if(root.left != null || root.right != null) {
TreeNode temp = invertTree(root.left);
root.left = invertTree(root.right);
root.right = temp;
}

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.

두 자식이 모두 null일 때, 어차피 null끼리 스왑해도 결과가 같으니까, if(root.left != null || root.right != null) 조건문이 없는게 더 가독성 측면에서 좋을 것 같아요~!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

그렇네요. 편향트리에서 null 케이스가 나왔을 때 거기까지 생각이 미쳤어야 했네요. 코멘트 감사합니다 :)

@dahyeong-yun
dahyeong-yun merged commit 3be4f48 into DaleStudy:main Aug 29, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Aug 29, 2026
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