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
21 changes: 21 additions & 0 deletions coin-change/parkhojeong.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.

sys.maxsize로 최대값을 설정할 수 있군요!
많이 배워갑니다.

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 금액별 최소 동전 개수를 구하기 위해 각 금액에 대해 최소 비용을 판단하는 DP 방식으로 구현되어 있습니다. 부분 문제의 해를 이용해 전체 문제의 해를 구성하는 전형적인 DP 패턴입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(amount * len(coins))
Space O(amount)

피드백: 초기 dp 배열을 1/0으로 구성하는 접근은 각 금액에 도달 가능한지 여부를 저장하는 방식으로 작동한다. 다만 초기화 및 업데이트 로직이 잘못될 경우 일부 경우에서 -1 처리와 경계 조건이 누락될 수 있다.

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

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
if amount == 0:
return 0

dp = [1 if x in coins else 0 for x in range(amount + 1)]
MAX_VALUE = sys.maxsize

for i in range(1, amount + 1):
if dp[i] != 0:
continue

dp[i] = MAX_VALUE
for coin in coins:
if i - coin > 0 and dp[i - coin] > 0:
dp[i] = min(dp[i - coin] + 1, dp[i])

if dp[amount] == MAX_VALUE:
return -1

return dp[amount]
15 changes: 15 additions & 0 deletions find-minimum-in-rotated-sorted-array/parkhojeong.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.

혹시 슬라이싱을 쓰신 이유가 있으실까요?
슬라이싱은 그 크기만큼 O(N) 시간복잡도라 빠르진 않을것 같아서요,
문자열은 immutable 한 객체라서 새로 복사해서 주는 방식으로 작동하잖아요

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.

혹시 슬라이싱을 쓰신 이유가 있으실까요? 슬라이싱은 그 크기만큼 O(N) 시간복잡도라 빠르진 않을것 같아서요, 문자열은 immutable 한 객체라서 새로 복사해서 주는 방식으로 작동하잖아요

@alphaorderly 이미 머지된 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.

이건 사담인데

[3, 1] 테스트 케이스에 대하여, mid_idx=1이 되고, 아래의 코드에서 nums[mid_idx + 1:]nums[2:]로 되어서 인덱스 에러가 날 줄 알았는데, 안나는군요!
리뷰할 때마다 새로운 사실을 알아가게 되네요.

            else:
                nums = nums[mid_idx + 1:]

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.

파이썬이 range 넘어가는 경우엔 빈 배열로 되는 것을 사용해보았습니다. 근데 이 풀이는 슬라이싱이 O(n)의 복잡도라 최적화 진행해봤습니다. 31ba2f4

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.

이건 사담인데

[3, 1] 테스트 케이스에 대하여, mid_idx=1이 되고, 아래의 코드에서 nums[mid_idx + 1:]nums[2:]로 되어서 인덱스 에러가 날 줄 알았는데, 안나는군요! 리뷰할 때마다 새로운 사실을 알아가게 되네요.

        else:
            nums = nums[mid_idx + 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search
  • 설명: 정렬된 배열이 회전되었을 때 최소 원소를 이진 탐색으로 찾는 방식으로, 구간을 절반으로 줄이며 조건에 따라 lo/hi를 조정합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(log n)
Space O(1)

피드백: 적절한 이분탐색 로직으로 회전 포인트를 찾고 있다. 루프 내에서 최소값 비교 조건이 명확하다.

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

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def findMin(self, nums: List[int]) -> int:
lo, hi = 0, len(nums) - 1
while lo < hi:
mid = (lo + hi) // 2

if nums[lo] < nums[hi]:
return nums[lo]

if nums[mid] < nums[hi]:
hi = mid
else:
lo = mid + 1

return nums[lo]
15 changes: 15 additions & 0 deletions maximum-depth-of-binary-tree/parkhojeong.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 리프까지 트리를 깊이 우선 탐색하여 각 가지의 깊이를 재귀적으로 구하고 최대 깊이를 반환하므로 DFS 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(h)

피드백: 트리의 모든 노드를 방문하며 각 재귀 호출이 깊이를 증가시키는 전형적인 DFS 방식이다.

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

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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 maxDepth(self, root: Optional[TreeNode]) -> int:
return self.dfs(root, 0)

def dfs(self, root, depth) -> int:
if not root:
return depth

return max(self.dfs(root.left, depth + 1), self.dfs(root.right, depth + 1))
25 changes: 25 additions & 0 deletions merge-two-sorted-lists/parkhojeong.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Linked List
  • 설명: 두 개의 정렬된 연결리스트를 한 리스트로 병합하는 과정에서 포인터 두 개로 순회하며 값을 비교하여 순서를 맞추는 패턴이다. 남은 부분을 한꺼번에 붙이는 방식이 특징이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(1)

피드백: 병합 과정이 루프를 통해 선형적으로 진행되며 안정적으로 동작한다.

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

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
dummy_head = ListNode()
cur = dummy_head

while list1 and list2:
if list1.val <= list2.val:
cur.next = list1
list1 = list1.next
else:
cur.next = list2
list2 = list2.next
cur = cur.next

if list1:
cur.next = list1
elif list2:
cur.next = list2

return dummy_head.next
51 changes: 51 additions & 0 deletions word-search/parkhojeong.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.

이거 풀이 1900ms 나오는데 0ms까지 줄일수 있는거 아시나요? 한번 시도해보시는것도 재밌으실거에요!

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.

오 한 번 시도 해보곘습니다. 리뷰 감사합니다!

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.

backtrackDIRECTIONS, MARKER를 사용한 풀이가 직관적으로 이해가 잘 되서 좋네요!

@parkhojeong parkhojeong Jul 18, 2026

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.

대문자 케이싱을 사용하면 가독성이 괜찮더라구요. 빈도 기반으로 체크하는 로직은 초기 한 번만 하면 되서 정리해보았습니다. 994aca2

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, Depth-First Search, Hash Map / Hash Set
  • 설명: 단어 탐색 문제에서 DFS로 격자를 탐색하며 각 위치에서 다음 글자를 확인하고, 방문 표시를 통해 백트래킹하는 방식이 핵심이다. 또한 글자 빈도 체크를 위한 해시 맵 사용도 포함된다.

📊 시간/공간 복잡도 분석

복잡도
Time O(N * 4^L)
Space O(L)

피드백: 사전 검사로 문자 빈도와 방향 탐색을 최적화하려고 시도한다. 백트래킹 시 중복 방문 제어가 핵심이다.

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

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from collections import Counter
from typing import List

class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
row_len, col_len = len(board), len(board[0])

board_freq = Counter(ch for row in board for ch in row)

for ch, need in Counter(ch for ch in word).items():
if board_freq.get(ch, 0) < need:
return False

if board_freq.get(word[0], 0) > board_freq.get(word[-1], 0):
word = word[::-1]

DIRECTIONS = ((-1, 0), (1, 0), (0, -1), (0, 1))
MARKER = ""

def in_bounds(r: int, c: int) -> bool:
return 0 <= r < row_len and 0 <= c < col_len

def backtrack(r: int, c: int, idx: int) -> bool:
if idx == len(word) - 1:
return True

saved_char = board[r][c]
board[r][c] = MARKER
board_freq[saved_char] -= 1

for dr, dc in DIRECTIONS:
nr, nc = r + dr, c + dc
next_ch = word[idx + 1]

if (in_bounds(nr, nc)
and board[nr][nc] != MARKER
and board[nr][nc] == next_ch
and board_freq[next_ch] > 0
and backtrack(nr, nc, idx + 1)):
return True

board[r][c] = saved_char
board_freq[saved_char] += 1
return False

for r in range(row_len):
for c in range(col_len):
if board[r][c] == word[0] and backtrack(r, c, 0):
return True

return False
Loading