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
19 changes: 19 additions & 0 deletions container-with-most-water/sangbeenmoon.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
  • 설명: 두 포인터(left, right)를 사용해 경계에서 가능한 면적을 계산하고, 높이가 작은 쪽을 포인터를 이동시키는 방식으로 최적 해를 찾는 패턴이며, 각 단계에서 현재 최댓값과 조건 판단이 포함되어 있어 그리디 성향도 보입니다.

📊 시간/공간 복잡도 분석

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

피드백: 왼쪽/오른쪽 포인터를 한 칸씩 이동하며 현재 구간의 넓이를 갱신한다. 두 높이 중 작은 쪽을 늘리면 더 큰 넓이가 나올 수 있는 가능성을 남기고 버려진 부분을 제거한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def maxArea(self, height: List[int]) -> int:

left = 0
right = len(height) - 1

answer = 0

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

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

return answer
49 changes: 49 additions & 0 deletions design-add-and-search-words-data-structure/sangbeenmoon.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, Backtracking
  • 설명: 단어를 트리 형태로 구성하는 Trie(접두어 트리) 구조를 사용하며, 검색 시 '.' 와일드카드로 모든 자식 노드를 재귀 탐색하는 부분은 백트래킹의 탐색 흐름으로 작동합니다.

📊 시간/공간 복잡도 분석

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

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

피드백: 문자별로 자식 노드를 구성하고 끝에 도달하면 is_end 를 True로 마킹한다.

개선 제안: 일반적인 순회 방식으로 재귀 깊이가 증가할 수 있어 스택 오버플로우 위험을 고려해 비재귀 구현도 검토해볼 수 있습니다.

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

피드백: 점(.)을 사용한 모든 경로를 탐색하므로 최악의 경우 탐색 비용이 커질 수 있습니다.

개선 제안: 실제 사용에서 점(.)의 사용 비율이 낮다면 트라이의 가지 수를 줄이는 방향으로 최적화 가능.

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

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

def __init__(self):
self.children = {}
self.is_end = False



def addWord(self, word: str, i=0) -> None:
if i >= len(word):
self.is_end = True
return

target_char = word[i]

if target_char in self.children:
node = self.children[target_char]
node.addWord(word, i+1)
else:
node = WordDictionary()
self.children[target_char] = node
node.addWord(word, i+1)


def search(self, word: str, i=0) -> bool:
if i >= len(word):
return self.is_end

target_char = word[i]

if target_char == ".":
for child_node in self.children.values():
if child_node.search(word,i+1) == True:
return True

if target_char in self.children:
node = self.children[target_char]
return node.search(word, i+1)
else:
node = WordDictionary()
return node.search(word, i+1)
Comment on lines +40 to +41

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.

이부분은 맞는 단어가 없다는거니까 return False를 하는게 더 맞지 않을까 생각해요!





# Your WordDictionary object will be instantiated and called as such:
# obj = WordDictionary()
# obj.addWord(word)
# param_2 = obj.search(word)
53 changes: 53 additions & 0 deletions longest-increasing-subsequence/sangbeenmoon.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, Binary Search, Greedy, Monotonic Stack
  • 설명: 최대 증가 부분수열 LIS를 DP로 해결하는 부분과 이분탐색을 이용한 최적화(긴 증가 부분수열의 길이를 이분탐색으로 관리)로 구성되어 있습니다. 또한 순서를 유지하며 수열을 관리하는 과정은 그리디/단순 비교로 구현됩니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.lengthOfLIS — Time: O(n log n) / Space: O(n)
복잡도
Time O(n log n)
Space O(n)

피드백: 이분 탐색을 이용한 LIS 배열 유지 방식으로 최적의 길이를 효율적으로 구한다.

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

풀이 2: Solution.lengthOfLIS — Time: O(n^2) / Space: O(n)
복잡도
Time O(n^2)
Space O(n)

피드백: 직관적이지만 시간 복잡도가 커져 큰 입력에서 비효율적이다.

개선 제안: 필요 시 이분탐색 기반으로 전환하는 것을 권장.

풀이 3: Solution.lengthOfLIS — Time: O(n log n) / Space: O(n)
복잡도
Time O(n log n)
Space O(n)

피드백: bisect_left를 사용하여 시퀀스의 적절한 위치를 업데이트한다.

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,56 @@ def lengthOfLIS(self, nums: List[int]) -> int:
seq[i] = num

return len(seq)







# ------------

# TC : O(n^2)

class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:

dp = [1] * len(nums)
for i, num in enumerate(nums):

max_val = 1

for j in range(0, i):
if nums[j] < num:
max_val = max(max_val, dp[j] + 1)

dp[i] = max_val

return max(dp)


# -----------

# TC : O(nlogn)

from bisect import bisect_left

class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:

seq = []

for i, num in enumerate(nums):
if i == 0:
seq.append(num)
continue

last = seq[len(seq) - 1]
if last < num:
seq.append(num)
elif last > num:
target_idx = bisect_left(seq, num)
seq[target_idx] = num

return len(seq)

49 changes: 49 additions & 0 deletions spiral-matrix/sangbeenmoon.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, Depth-First Search, Backtracking, Greedy, Hash Map / Hash Set, Dynamic Programming, Binary Search, Monotonic Stack, Heap / Priority Queue, Divide and Conquer, Union Find, Trie, Bit Manipulation, BFS, DFS, Sliding Window, Fast & Slow Pointers
  • 설명: 스파이럴 행렬 순회를 구현하기 위해 방향 순회와 방문 여부 추적을 사용합니다. 재귀 DFS와 반복 루프 두 가지 구현이 제시되며, 인접 원소 방향 전환과 방문 체크로 순회 경로를 구성합니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.spiralOrder — Time: O(m*n) / Space: O(m*n)
복잡도
Time O(m*n)
Space O(m*n)

피드백: 방문 여부를 추적하며 한 방향으로 진행하고 벽에 닿으면 방향을 바꾼다.

개선 제안: DFS 방식은 스택 깊이가 큼에 따라 재귀 한계를 주의. 반복 구현으로 바꾸면 안전.

풀이 2: Solution.spiralOrder — Time: O(m*n) / Space: O(m*n)
복잡도
Time O(m*n)
Space O(m*n)

피드백: 명시적으로 현재 위치와 방향을 관리하여 순환한다.

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,52 @@ def dfs(xx: int, yy:int, d:int):
dfs(0,0,0)

return answer





# ---------



# 우 -> 하 -> 좌 -> 상

class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:

answer = []

dx = [1,0,-1,0]
dy = [0,1,0,-1]

row_len , col_len = len(matrix), len(matrix[0])
visited = [[False] * col_len for _ in range(row_len)]

xx = 0
yy = 0
answer.append(matrix[yy][xx])
visited[yy][xx] = True

if len(answer) == row_len * col_len:
return answer

d = 0
while True:
nx = xx + dx[d]
ny = yy + dy[d]
if 0 <= nx and nx < col_len and 0 <= ny and ny < row_len:
if not visited[ny][nx]:
answer.append(matrix[ny][nx])
visited[ny][nx] = True

if len(answer) == row_len * col_len:
break

xx = nx
yy = ny
continue
d = 0 if d == 3 else d + 1

return answer

Loading