Skip to content
Open
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
33 changes: 33 additions & 0 deletions 3sum/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Hash Map / Hash Set, Greedy, Dynamic Programming
  • 설명: 해당 코드는 중복 처리와 쿼리용 해시 맵( Counter ) 사용으로 조건을 빠르게 확인하고, 정렬된 고유 값 배열에서 두 포인터처럼 순회 흐름을 만들어 삼중합을 찾는 구조를 보이며, 해시 맵으로 존재 여부를 확인하는 점이 핵심 패턴이다.

📊 시간/공간 복잡도 분석

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

피드백: 중복 조합을 피하기 위한 정렬과 두 포인터 탐색 로직이 들어 있습니다. 해시맵을 쓰지 않더라도 시간 복잡도는 두 포인터 탐색으로 달성됩니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# TC: O(N^2)
# SC: O(N)
class Solution:
def threeSum(self, nums: list[int]) -> list[list[int]]:

cnt_dict = Counter(nums)
nums_uniq = sorted(cnt_dict.keys())
n = len(nums_uniq)

ret = []

for num in cnt_dict.keys():
if num == 0:
if cnt_dict[num] >= 3:
ret.append([0, 0, 0])
elif cnt_dict[num] >= 2 and num * 2 * -1 in cnt_dict:
ret.append([num, num, num * 2 * -1])

for idx1, num1 in enumerate(nums_uniq):
if num1 > 0:
break

for idx2 in range(idx1 + 1, n):
num2 = nums_uniq[idx2]
num3 = (num1 + num2) * -1

if num2 >= num3:
break
elif num3 in cnt_dict:
ret.append([num1, num2, num3])

return ret

15 changes: 15 additions & 0 deletions climbing-stairs/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Two Pointers
  • 설명: 클라이밍 스테어 문제는 피보나치 형태의 DP로 점화식을 이용해 각 단계의 경우의 수를 누적 계산합니다. 변수 간의 관계를 따라가며 상태를 갱신하는 전형적인 동적계획(DP) 패턴이며, 상호 의존적인 두 이전 상태를 이용하는 점에서 Two Pointers로도 간주될 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 상태를 두 변수로만 유지하여 추가 공간 없이 계단 수를 계산합니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TC: O(N)
# SC: O(1)
class Solution:
def climbStairs(self, n: int) -> int:

one_down = 1
two_down = 0

for _ in range(1, n):
cur = two_down + one_down
two_down = one_down
one_down = cur

return two_down + one_down

25 changes: 25 additions & 0 deletions product-of-array-except-self/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Dynamic Programming, Hash Map / Hash Set, Divide and Conquer, Greedy
  • 설명: 배열 전후 누적 곱을 미리 계산하는 방식으로 각 원소를 제외한 곱을 구하는 풀이로, 부분문제를 이용한 재사용과 누적값 저장이 핵심이다. 두 포인터의 연쇄적 인덱스 접근과 누적 곱 배열 사용으로 최적화된다.

📊 시간/공간 복잡도 분석

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

피드백: 두 보조 배열을 사용해 각 원소를 제외한 곱을 얻는 전형적인 방법이다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# TC: O(N)
# SC: O(N)
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:

n = len(nums)
prefix_prod = [0] * n
suffix_prod = [0] * n

prefix_prod[0] = nums[0]
suffix_prod[-1] = nums[-1]

for idx in range(1, n):
prefix_prod[idx] = prefix_prod[idx - 1] * nums[idx]
suffix_prod[-idx - 1] = suffix_prod[-idx] * nums[-idx - 1]

ret = []

ret.append(suffix_prod[1])
for idx in range(1, n - 1):
ret.append(prefix_prod[idx - 1] * suffix_prod[idx + 1])
ret.append(prefix_prod[n - 2])

return ret

13 changes: 13 additions & 0 deletions valid-anagram/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 두 문자열의 문자를 개수로 비교하기 위해 해시 맵(카운터)을 사용해 빈도수를 비교합니다. 길이 일치 여부로 간단한 선조치를 하고, 최종적으로 두 카운터의 동등성을 확인합니다.

📊 시간/공간 복잡도 분석

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

피드백: Counter를 사용해 두 문자열의 문자 분포를 비교한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# TC: O(N)
# SC: O(1)
class Solution:
def isAnagram(self, s: str, t: str) -> bool:

if len(s) != len(t):
return False

cnt_s = Counter(s)
cnt_t = Counter(t)

return cnt_s == cnt_t

23 changes: 23 additions & 0 deletions validate-binary-search-tree/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Depth-First Search, Divide and Conquer
  • 설명: BST 유효성 검사에서 각 노드에 대해 허용 범위를 재귀적으로 좁혀가며 왼쪽은 작고 오른쪽은 커야 한다는 규칙을 검사한다. 트리를 깊이 우선으로 탐색하며 각 단계에서 분할된 하위 문제로 재귀 호출한다.

📊 시간/공간 복잡도 분석

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

피드백: 각 노드에 대해 왼쪽/오른쪽 자식의 범위를 재귀적으로 확인한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# TC: O(N)
# SC: O(H)
# 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 isValid(self, left_bound, right_bound, root):
if root is None:
return True
if left_bound is not None and left_bound >= root.val:
return False
if right_bound is not None and right_bound <= root.val:
return False

return self.isValid(left_bound, root.val, root.left) and self.isValid(root.val, right_bound, root.right)

def isValidBST(self, root: Optional[TreeNode]) -> bool:
return self.isValid(None, root.val, root.left) and self.isValid(root.val, None, root.right)

Loading