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
22 changes: 22 additions & 0 deletions container-with-most-water/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, Greedy
  • 설명: 좌우 포인터를 이용해 서로를 좁혀가며 용량을 계산하는 방식으로 최댓값을 탐색합니다. 각 단계에서 더 작은 벽에 맞춰 포인터를 이동해 최적 해를 빨리 찾는 그리디 특성을 가집니다.

📊 시간/공간 복잡도 분석

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

피드백: 왼쪽/오른쪽 포인터를 한 칸씩만 이동시키며 최댓값을 갱신한다. 루프는 배열 길이에 비례해 수행된다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TC: O(N)
# SC: O(1)
class Solution:
def maxArea(self, height: List[int]) -> int:
l = 0
r = len(height) - 1
max_height = max(height)
ans = 0

while l < r:
ans = max(ans, min(height[l], height[r]) * (r - l))

if ans > max_height * (r - l):
return ans

if height[l] < height[r]:
l += 1
else:
r -= 1

return ans

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

제 생각에 너무 좋은 코드인데요, Python의 타입 힌팅을 적극적으로 이제 활용해 보시면 코드의 가독성에 큰 긍정적 영향을 줄것이라고 생각해요!
특히 메서드를 추가 작성할때 input param들의 타입과 return type을 작성하면 개인적으로는 상당한 가독성의 향상이 있다고 생각합니다.

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 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie, Backtracking, Dynamic Programming
  • 설명: 코드는 트라이(Trie) 자료구조를 활용해 단어를 저장하고 검색합니다. 검색에서 '.' 와일드카드를 재귀적으로 대입해 가능한 경로를 탐색하므로 부분적으로 백트래킹 패턴이 보이고, 트라이 기반의 저장과 탐색으로 문제의 문자열 매칭을 구현합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(len(word))
Space O(total_chars_inserted)

피드백: 트라이 구조로 단어를 저장하고 와일드카드를 재귀로 확장 탐색한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class WordDictionary:

def __init__(self):
self.trie = {}

def addWord(self, word: str) -> None:
cur = self.trie

for c in word:
if c not in cur:
cur[c] = {}
cur = cur[c]

cur[0] = True

def search(self, word: str) -> bool:

n = len(word)

def rec(cur: dict, idx: int) -> bool:
if idx == n:
return 0 in cur

if word[idx] == '.':
for next in cur:
if next == 0:
continue
if rec(cur[next], idx + 1):
return True
return False
else:
if word[idx] in cur:
return rec(cur[word[idx]], idx + 1)
else:
return False

return rec(self.trie, 0)

15 changes: 15 additions & 0 deletions longest-increasing-subsequence/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, Dynamic Programming
  • 설명: LIS 길이를 이분 탐색으로 최적화하는 대표적인 방법으로, arr를 유지하며 각 원소의 삽입 위치를 이분 탐색으로 찾는 패턴입니다. 이로써 O(N log N) 시간 복잡도가 가능해집니다.

📊 시간/공간 복잡도 분석

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

피드백: 이분검색으로 LIS의 길이를 효율적으로 관리한다.

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

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

for num in nums:
if len(arr) == 0 or arr[-1] < num:
arr.append(num)
else:
idx = bisect_left(arr, num)
arr[idx] = num

return len(arr)

26 changes: 26 additions & 0 deletions spiral-matrix/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.

와 이건 코드를 아트의 경지로 올리셨군요 ㄷㄷㄷ 대단하십니다.
배우고 갑니다!

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, Hash Map / Hash Set, Greedy, Divide and Conquer, Binary Search, Dynamic Programming, Breadth First Search, Depth First Search, Backtracking, Union Find, Trie, Bit Manipulation, Heap / Priority Queue, Sliding Window, Fast & Slow Pointers, DFS, BFS
  • 설명: 해당 코드는 행렬을 순회하여 나선형으로 방문하는 방식으로 인덱스를 좌우로 움직이며 모든 원소를 연속적으로 수집한다. 방향 전환과 경계 축소를 반복하는 구조는 Two Pointers의 응용으로 볼 수 있다.

📊 시간/공간 복잡도 분석

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

피드백: 끝까지 각 원소를 한 번씩 방문하는 방식으로 구현되어 있다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# TC: O(N*M)
# SC: O(N*M)
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:

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.

진짜 깔끔하게 푸셨네요. 리뷰하러 왔다가 배워갑니다..!!!

n = len(matrix)
m = len(matrix[0])
ans = []
row, col, dir = 0, -1, 1

n -= 1

while n >= 0 and m >= 1:
for i in range(0, m):
col += dir
ans.append(matrix[row][col])

for i in range(0, n):
row += dir
ans.append(matrix[row][col])

n -= 1
m -= 1
dir *= -1

return ans;

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack, Hash Map / Hash Set
  • 설명: 괄호 유효성 검사에서 스택을 이용해 여는 괄호를 저장하고 닫는 괄호가 올바르게 매칭되는지 확인하므로 Stack 패턴에 해당하며, 매칭 규칙을 해시맵으로 빠르게 조회하므로 Hash Map / Hash Set 패턴도 함께 해당됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 문자열을 한 번 순회하며 스택으로 매칭 여부를 판단한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TC: O(N)
# SC: O(N)
class Solution:
def isValid(self, s: str) -> bool:
pars = {'(': ')', '{': '}', '[': ']'}
stack = []

for c in s:
if c in pars:
stack.append(c)
else:
if not stack or pars[stack.pop()] != c:
return False

return len(stack) == 0

Loading