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
18 changes: 18 additions & 0 deletions container-with-most-water/daehyun99.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 포인터를 이용해 두 줄 사이의 면적을 탐색하며, 매 단계에서 더 작은 높이에 의해 최적 해를 찾아가는 패턴입니다. 공간은 상수, 시간은 선형으로 빠르게 해결합니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.maxArea — Time: ✅ O(N) → O(n) / Space: ✅ O(1) → O(1)
유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(1) O(1)

피드백: 투 포인터로 양 끝을 유지하며 면적을 계산하고 포인터를 움직여 중복 계산을 피한다.

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

풀이 2: WordDictionary.addWord — Time: O(k) / Space: O(sum of nodes)
복잡도
Time O(k)
Space O(sum of nodes)

피드백: 해당 단어의 각 문자마다 트리에 노드를 생성하거나 이동한다. 단어 길이를 k라 할 때 시간은 O(k).

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

풀이 3: WordDictionary.search — Time: O(?) / Space: O(?)
복잡도
Time O(?)
Space O(?)

피드백: 검색 시 불확실한 경우 모든 경로를 탐색하므로 최악의 경우 지수적일 수 있다. 문자열 길이와 트리의 구조에 따라 다름.

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

풀이 4: Solution.lengthOfLIS — Time: ❌ O(N) → O(n^2) / Space: ❌ O(1) → O(n)
유저 분석 실제 분석 결과
Time O(N) O(n^2)
Space O(1) O(n)

피드백: 두 중첩 루프를 통해 모든 이전 원소를 확인하며 LIS를 갱신한다.

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

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

피드백: 네 방향으로의 경계 축소를 통해 모든 원소를 방문한다.

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

풀이 6: Solution.isValid — Time: O(n) / Space: O(n)
복잡도
Time O(n)
Space O(n)

피드백: 스택에 남은 괄호 쌍으로 유효성 판단을 수행한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Time: O(N)
# Space: O(1)
class Solution:
def maxArea(self, height: List[int]) -> int:
size = 0
l, r = 0, len(height)-1
length = len(height)-1

while l < r:
if height[l] < height[r]:
size = max(size, height[l] * length)
l += 1
length -= 1
else:
size = max(size, height[r] * length)
r -= 1
length -= 1
return size
39 changes: 39 additions & 0 deletions design-add-and-search-words-data-structure/daehyun99.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, Hash Map / Hash Set, Breadth-First Search
  • 설명: 단어를 트라이 형태로 구현하고(각 문자 간 노드로 연결), 검색 시 점(.) 와일드카드를 다중 경로로 확장하기 위해 BFS를 활용합니다. 해시맵으로 자식을 표현하고, 트라이 구조를 이용해 문자열 매칭을 빠르게 수행합니다.

📊 시간/공간 복잡도 분석

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

풀이 1: WordDictionary.addWord — Time: O(k) / Space: O(number of nodes)
복잡도
Time O(k)
Space O(number of nodes)

피드백: 키 문자마다 트리에 노드를 생성하거나 이동하며 공간 복잡도는 단어 길이에 비례한다.

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

풀이 2: WordDictionary.search — Time: 복잡도는 문자열과 트리 구조에 따라 달라짐 / Space: O(depth of tree)
복잡도
Time 복잡도는 문자열과 트리 구조에 따라 달라짐
Space O(depth of tree)

피드백: '.'의 확장으로 가능 경로가 급증할 수 있어 최악의 경우 비효율적일 수 있다.

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

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

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

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

def addWord(self, word: str) -> None:
pointer = self.root
for char in word:
if char in pointer:
pointer = pointer[char]
else:
pointer[char] = {}
pointer = pointer[char]
pointer["0"]={}

def search(self, word: str) -> bool:
from collections import deque
pointer = self.root
que = deque()
que.append(pointer)

for char in word:
for i in range(len(que)):
pointer = que.popleft()
if char in pointer:
que.append(pointer[char])
elif char == ".":
for key in pointer.keys():
que.append(pointer[key])
while len(que) > 0:
pointer = que.popleft()
if "0" in pointer:
return True
return False

# Your WordDictionary object will be instantiated and called as such:
# obj = WordDictionary()
# obj.addWord(word)
# param_2 = obj.search(word)
11 changes: 11 additions & 0 deletions longest-increasing-subsequence/daehyun99.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
  • 설명: 주어진 코드는 LIS를 각 위치에서 최대 증가 길이를 저장하는 DP 형태로 풀이한다. 이중 루프로 구성되어 O(n^2) 시간 복잡도를 가지며, 부분문제의 해를 이용해 전체 최적해를 구하는 DP 패턴에 속한다.

📊 시간/공간 복잡도 분석

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

피드백: 각 i에 대해 j < i를 확인해 증가하는 경우 최댓값으로 갱신한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Time: O(N**2)
# Space: O(N)
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
counts = [1 for i in nums]

for i in range(1, len(nums)):
for j in range(0, i):
if nums[j] < nums[i]:
counts[i] = max(counts[i], counts[j]+1)
return max(counts)
55 changes: 55 additions & 0 deletions spiral-matrix/daehyun99.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, Monotonic Stack, Divide and Conquer, Dynamic Programming, Binary Search, Hash Map / Hash Set, Breadth-First Search, Depth-First Search, Backtracking, Union Find, Trie, Bit Manipulation, Heap / Priority Queue, Sliding Window, Fast & Slow Pointers, DFS, BFS
  • 설명: 스파이럴 순회는 격자의 경계로 순차적으로 방문하는 패턴으로, 방향 배열과 경계 업데이트를 통해 부분 배열을 차례로 방문하는 방식이다. 이를 통해 배열의 원소를 순서대로 모으는 과정을 구현한다.

📊 시간/공간 복잡도 분석

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

피드백: 경계값과 방향 순서를 잘 관리하면 모든 원소를 한 번씩 방문한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
height = len(matrix)
weight = len(matrix[0])
adding = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0]
]
m = 0
n = -1
size = height * weight
count = 0

result = []

while count < size:
if 0 < weight and count < size:
m_add, n_add = adding[0]
for _ in range(weight):
m += m_add
n += n_add
result.append(matrix[m][n])
count += 1

height -= 1
if 0 < height and count < size:
m_add, n_add = adding[1]
for _ in range(height):
m += m_add
n += n_add
result.append(matrix[m][n])
count += 1

weight -= 1
if 0 < weight and count < size:
m_add, n_add = adding[2]
for _ in range(weight):
m += m_add
n += n_add
result.append(matrix[m][n])
count += 1

height -= 1
if 0 < height and count < size:
m_add, n_add = adding[3]
for _ in range(height):
m += m_add
n += n_add
result.append(matrix[m][n])
count += 1

weight -= 1
return result
16 changes: 16 additions & 0 deletions valid-parentheses/daehyun99.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
  • 설명: 문자열의 괄호를 스택으로 관리하여 최근 여는 괄호와 닫는 괄호를 짝지어 제거하는 방식으로 올바른 괄호 여부를 판단한다. 연속된 두 문자로 된 부분 문자열의 매칭을 확인하는 것이 핵심이다.

📊 시간/공간 복잡도 분석

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

피드백: 괄호 매칭을 스택으로 처리하는 일반적인 방법이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def isValid(self, s: str) -> bool:
stack = []

map = {"()", "{}", "[]"}

for char in s:
stack.append(char)
if len(stack) >= 2:
if ''.join(stack[-2:]) in map:
stack.pop()
stack.pop()
if len(stack) == 0:
return True
else:
return False
Loading