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
18 changes: 18 additions & 0 deletions container-with-most-water/njngwn.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, Greedy
  • 설명: 좌우 포인터를 이동시키며 최댓값을 갱신하는 방식으로 면적을 계산하는 이중 포인터 패턴과, 매 단계에서 더 작은 벽을 포기하는 결정으로 최적 해를 점진적으로 탐색하는 그리디 성격이 보입니다.

📊 시간/공간 복잡도 분석

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

피드백: 좌우 포인터를 한 칸씩 이동시키며 전체를 한 번만 훑는 방법으로 최댓값을 구한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
# Time Complexity: O(n), n: len(height)
# Space Complexity: O(1)
def maxArea(self, height: List[int]) -> int:
left, right = 0, len(height) - 1
max_area = 0

while left < right:
w = right - left
h = min(height[left], height[right])
max_area = max(max_area, w * h)

if height[left] <= height[right]:
left += 1
else:
right -= 1

return max_area
42 changes: 42 additions & 0 deletions design-add-and-search-words-data-structure/njngwn.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie, Depth-First Search, Backtracking
  • 설명: Trie를 이용해 단어를 저장하고 탐색하며, '.' 와일드카드를 재귀 DFS로 처리하는 구조로 패턴은 Trie와 DFS(Backtracking의 한 형태) 입니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: WordDictionary.addWord — Time: O(L) / Space: O(TotalNodes)
복잡도
Time O(L)
Space O(TotalNodes)

피드백: 트라이를 이용해 문자열 삽입 및 탐색을 구현했다. 삽입/공간 비용은 단어 길이에 비례한다.

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

풀이 2: WordDictionary.search — Time: O(Branching^W) / Space: O(H)
복잡도
Time O(Branching^W)
Space O(H)

피드백: 와일드카드 탐색으로 최악의 경우 다수의 경로를 탐색할 수 있다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class TrieNode:
def __init__(self):
self.children = {}
self.isEnd = False


class WordDictionary:

def __init__(self):
self.root = TrieNode()

def addWord(self, word: str) -> None:
node = self.root
for ch in word:
if ch not in node.children:
node.children[ch] = TrieNode()
node = node.children[ch]

node.isEnd = True

def search(self, word: str) -> bool:
def dfs(node: TrieNode, idx: int) -> bool:
if idx == len(word):
return node.isEnd

ch = word[idx]
if ch == '.':
for child in node.children.values():
if dfs(child, idx + 1):
return True
return False
else:
if ch not in node.children:
return False
return dfs(node.children[ch], idx + 1)

Comment on lines +30 to +36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ch == '.'인 경우 마지막에 return False로 종료되므로, else를 제거하면 중첩 깊이를 줄여 코드를 조금 더 간결하게 작성할 수 있을 것 같습니다!

return dfs(self.root, 0)

# Your WordDictionary object will be instantiated and called as such:
# obj = WordDictionary()
# obj.addWord(word)
# param_2 = obj.search(word)
23 changes: 23 additions & 0 deletions longest-increasing-subsequence/njngwn.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, Dynamic Programming, Greedy
  • 설명: 수열의 증가 부분수열 길이를 이분 탐색으로 갱신하는 패턴으로, LIS 문제에서 부분수열의 길이를 유지하며 최적화를 위해 이분 탐색을 사용합니다. DP 요소와 이분 탐색의 결합으로 O(n log n) 구현이 가능합니다.

📊 시간/공간 복잡도 분석

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

피드백: 이분 탐색으로 최적의 증가 부분 수열의 길이를 유지한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
# Time Complexity: O(n*log(n)), n: len(nums)
# Space Complexity: O(1)
Comment on lines +2 to +3

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.

seq가 최악의 경우 길이 n만큼 되서 SC는 O(n)이지 않을까요? ex. [1, 2, 3, 4, 5]

def lengthOfLIS(self, nums: List[int]) -> int:
seq = []

for num in nums:
if not seq or (seq[-1] < num):
seq.append(num)
continue

# insert with binary search

@parkhojeong parkhojeong Aug 1, 2026

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.

로직은 찾는 값보다 큰 값 중 가장 작은 데에 덮어 쓰는 동작으로 보이는데요. 주석을 insert, binary search 용어를 사용해서 적으신 이유가 있을까요? 지금 주석은 해당 값을 찾아서(탐색) 그 인덱스에 insert(python) 하는 동작으로 읽혀서요.

left, right = 0, len(seq)
while left < right:
mid = (left + right) // 2
if seq[mid] < num:
left = mid + 1
else:
right = mid
Comment on lines +13 to +19

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.

오 python bisect_left 랑 동일하게 구현하셨는데 원래 bisect_left 알고 계셨는지 궁금하네요. https://github.com/python/cpython/blob/7ce7f0bd8511410bf7c42cc5fc88dfafe07874b6/Lib/bisect.py#L74


seq[left] = num

return len(seq)
30 changes: 30 additions & 0 deletions spiral-matrix/njngwn.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, Monotonic Stack, Greedy, Divide and Conquer, Dynamic Programming
  • 설명: 스파이럴 순회는 방향 전환 및 경계 업데이트로 배열을 순차적으로 접근하는 패턴으로, 두 포인터를 이용한 연속 탐색과 경계 업데이트가 핵심이다. 방향 벡터와 네 방향으로의 순차 접근이 특징이다.

📊 시간/공간 복잡도 분석

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

피드백: 경계와 방향 관리가 복잡하지만 전체 원소를 한 번씩 방문한다.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

오른쪽, 아래, 왼쪽, 위 순서로 이동하면서 경계 범위를 점차 줄여 나가는 방식이 인상적이었습니다. 좋은 로직 잘 보고갑니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution:
# Time Complexity: O(n*m), n: len(matrix), m: len(matrix[0])
# Space Complexity: O(1)
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
result = []
direction = [(0, -1), (0, 1), (-1, 0), (1, 0)] # left, right, up, down
left, right, top, bottom = 0, len(matrix[0])-1, 0, len(matrix)-1 # borders
i, j, d = 0, 0, direction[1]

while left <= right and top <= bottom and 0 <= i < len(matrix) and 0 <= j < len(matrix[0]):
Comment on lines +9 to +10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

현재 방향 전환과 경계 갱신 로직이 정상적으로 동작한다면 i, j가 행렬 범위를 벗어날 일은 없을 것 같은데, while 조건에 좌표 범위 검사까지 추가하신 이유가 따로 있을까요? 어떤 의도로 작성하셨는지 궁금합니다!

# change direction and borders
if j == right and d == direction[1]:
d = direction[3] # right -> down
top += 1
elif i == bottom and d == direction[3]:
d = direction[0] # down -> left
right -= 1
elif j == left and d == direction[0]:
d = direction[2] # left -> up
bottom -= 1
elif i == top and d == direction[2]:
d = direction[1] # up -> right
left += 1

# append val to the result
result.append(matrix[i][j])
i += d[0]
j += d[1]

return result
25 changes: 25 additions & 0 deletions valid-parentheses/njngwn.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack / Queue (implemented as Deque), Greedy
  • 설명: 스택을 사용해 여는 괄호를 쌓고 닫는 괄호와 매칭하는 방식으로 구현되며, 올바른 함수 결과를 보장하기 위해 짝의 매칭 여부를 즉시 판단합니다. 이를 통해 선형 시간과 선형 공간 복잡도를 달성합니다.

📊 시간/공간 복잡도 분석

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

피드백: 짝이 맞지 않으면 즉시 False를 반환하도록 구현되어 있다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections import deque


class Solution:
# Time Complexity: O(n), n: len(s)
# Space Complexity: O(n), n: len(s)
def isValid(self, s: str) -> bool:
if len(s) % 2 != 0:
return False
Comment on lines +8 to +9

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

길이가 홀수인 경우 미리 반환해 불필요한 연산을 줄인 점이 좋네요!


stack = deque()

for ch in s:
if ch == '(' or ch == '[' or ch == '{':
stack.append(ch)
elif len(stack) != 0:
top = stack.pop()
if (top == '(' and ch == ')') or (top == '[' and ch == ']') or (top == '{' and ch == '}'):
continue
else:
return False
else:
return False

return len(stack) == 0
Loading