Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions course-schedule/radiantchoi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections import deque, defaultdict

class Solution:
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
posts = defaultdict(list)
indegree = [0] * numCourses

for prerequisite in prerequisites:
posts[prerequisite[1]].append(prerequisite[0])
indegree[prerequisite[0]] += 1

completed = 0
q = deque(list(filter(lambda x: indegree[x] == 0, range(numCourses))))

while q:
current = q.popleft()
completed += 1

for post in posts[current]:
indegree[post] -= 1

if indegree[post] == 0:
q.append(post)

return completed == numCourses
28 changes: 28 additions & 0 deletions invert-binary-tree/radiantchoi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Definition for a binary tree node.
* class TreeNode {
* val: number
* left: TreeNode | null
* right: TreeNode | null
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
* }
*/

function invertTree(root: TreeNode | null): TreeNode | null {
if (root === null) {
return null;
}

const temp = root.left;
root.left = root.right;
root.right = temp;

invertTree(root.left);
invertTree(root.right);

return root;
}
11 changes: 11 additions & 0 deletions jump-game/radiantchoi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def canJump(self, nums: List[int]) -> bool:
reachable = [False] * len(nums)
destination = len(nums) - 1

for index, strength in list(enumerate(nums))[::-1]:
if index + strength >= destination:
reachable[index] = True
destination = index

return reachable[0]
Copy link
Contributor

@doh6077 doh6077 Jan 17, 2026

Choose a reason for hiding this comment

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

안녕하세요 해당 풀이도 잘 풀어주셨는데,
reachable 리스트를 따로 만들지 않고 마지막에 return destination == 0으로 변경할 수 있을거 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오.. 그런 방법도 좋겠네요! 이 문제같은 경우는 풀 때 고생을 많이 했어서, "목적지부터 시작하여 시작점에서 이를 수 있는가" 라는 도식을 구현하는 데 집중했습니다. 사람의 인식과 효율적인 코드란 다를 수 있음을 새삼 느끼게 되네요.

41 changes: 41 additions & 0 deletions search-in-rotated-sorted-array/radiantchoi.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Solution {
func search(_ nums: [Int], _ target: Int) -> Int {
var left = 0
var right = nums.count - 1

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

// 일단, 찾았으면 바로 반환
if nums[mid] == target {
return mid
}

// 이 문제의 배열은 정렬되지 않은 것이 아니고, 정렬된 배열 두 개를 붙여 놨다고 생각하면 된다.
// 유효한 인덱스임이 보장된 left와 현재 인덱스인 mid를 비교한다.
if nums[left] <= nums[mid] {
// 이로써 left와 mid 사이가 이 "정렬된 부분"임을 체크한다.
// 정렬이 되어 있다면, 찾고자 하는 값이 이 "정렬된 범위" 내에 있는지 확인한다.
// left에서 >=를 이용한 이유는, left 자체가 정답 인덱스일 수도 있기 때문.
if target >= nums[left] && target < nums[mid] {
// 만약 그렇다면 통상적인 이진 탐색의 논리대로 가면 된다.
right = mid - 1
} else {
// 만약 그렇지 않다면 원래 갔어야 할 방향의 반대 방향으로 가면 된다.
left = mid + 1
}
} else {
// left와 mid 사이가 정렬이 틀어져 있다면, mid와 right 사이는 정렬되어 있는 것이다.
// 위와 동일하게 범위 확인을 하되, 방향을 반대로 가져가면 된다.
if target <= nums[right] && target > nums[mid] {
left = mid + 1
} else {
right = mid - 1
}
}
}

// early return하지 못했다면, 배열 내에 찾고자 하는 수가 없는 것이다.
return -1
}
}