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
31 changes: 31 additions & 0 deletions 3sum/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Sorting
  • 설명: 3Sum 문제를 이중 포인터(j, k)로 구성하고, 먼저 정렬한 뒤 양쪽 포인터로 합이 0이 되는 조합을 찾고 중복 제거를 수행합니다. 이 구조는 Two Pointers 패턴의 대표적 예시이며, 내부 루프에서 조건에 따라 포인터를 이동합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n^2)
Space O(1)

피드백: 정렬과 중복 제거를 통해 불필요한 계산을 피하고, 두 포인터의 이동으로 전체 시간 복잡도를 O(n^2)로 달성합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution:
def threeSum(self, nums: list[int]) -> list[list[int]]:
result_arr = []
n = len(nums)
nums.sort()

for i in range(n - 2):
if nums[i] > 0:
break
if i > 0 and nums[i] == nums[i - 1]:
continue

j = i + 1
k = n - 1
while j < k:
total = nums[i] + nums[j] + nums[k]

if total == 0:
result_arr.append([nums[i], nums[j], nums[k]])
while j < k and nums[j] == nums[j + 1]:
j += 1
while j < k and nums[k] == nums[k - 1]:
k -= 1
j += 1
k -= 1
elif total > 0:
k -= 1
else:
j += 1

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 클라이밍 스텝 문제는 두 가지 경우의 합으로 순서를 세는 DP 점화식으로 해결되며, 이전 상태를 이용해 현재 값을 구하는 전형적인 동적 계획법 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 선형 시간에 필요한 값들을 배열에 저장하며 해결합니다. 상용구의 간단한 최적화로 공간을 O(1)으로 줄일 수 있습니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def climbStairs(self, n: int) -> int:
if n == 1:
return 1

arr = [0] * n
arr[0], arr[1] = 1, 2

for i in range(2, n):
arr[i] = arr[i - 1] + arr[i - 2]

return arr[-1]

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

  1. 해당 문제에는 나눗셈을 쓰지 않도록 권장하고 있어요! 한번 시도해보시면 좋을 것 같아요
  2. 나눗셈을 쓰지 않는 방식을 사용하시면 자연스럽게 0의 갯수에 따른 edge case들을 신경쓰지 않아도 됩니다!

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
  • 설명: 두 개의 배열 순회로 각 원소의 左/右 곱을 미리 계산하는 방식으로, 한 번의 정방향/역방향 패스로 결과를 구성합니다. DP적 아이디어로 부분문제를 이용해 최종 결과를 얻지만 해시나 포인터 기반의 특정 구조는 사용되지 않습니다.

📊 시간/공간 복잡도 분석

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

피드백: 두 패스 구성으로 추가 공간 없이 각 위치의 곱을 계산합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
n = len(nums)
answer = [1] * n

for i in range(1, n):
answer[i] = answer[i -1] * nums[i - 1]

R = 1
for i in range(n - 1, -1, -1):
answer[i] *= R
R *= nums[i]

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 두 문자열의 문자 빈도를 해시 맵(Counter)으로 비교하여 같은지 확인하는 방식으로, 문자열 비교의 체크를 해시 기반 카운트로 해결합니다. 이 자체로는 그리디/탐색보다는 해시 맵 활용에 가까운 패턴이지만, 빈도 일치 여부를 빠르게 판단하는 해시 기반 접근입니다.

📊 시간/공간 복잡도 분석

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

피드백: Counter를 이용해 간결하게 구현되었고 선형 시간에 해결합니다.

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

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

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

class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return Counter(s) == Counter(t)
24 changes: 24 additions & 0 deletions validate-binary-search-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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Depth-First Search, Monotonic Stack, Hash Map / Hash Set
  • 설명: BST의 가능 여부를 재귀적으로 확인하며 각 노드에 대해 허용되는 값의 범위를 추적하는 방식으로 이분 탐색적 축약(범위 제한)과 DFS를 함께 활용합니다. 노드 방문은 좌/우 자식에 대해 범위를 갱신하며 조건 확인을 반복합니다.

📊 시간/공간 복잡도 분석

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

피드백: 각 노드에 대해 상한/하한을 전달해 BST 특성을 검사합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 isValidBST(self, root: Optional[TreeNode]) -> bool:
return self.dfs(root, ~sys.maxsize, sys.maxsize)

def dfs(self, root, min_val, max_val) -> bool:
val = root.val
if val <= min_val or val >= max_val:
return False

if root.left:
if not self.dfs(root.left, min_val, val):
return False
if root.right:
if not self.dfs(root.right, val, max_val):
return False

return True

Loading