Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4d5f428
week 1
alphaorderly Jun 27, 2026
3ac63f5
[alphaorderly] WEEK 02 Solutions
alphaorderly Jun 28, 2026
2536209
Merge branch 'DaleStudy:main' into main
alphaorderly Jun 28, 2026
612dbbb
fix: description에 맞게 코드 수정
alphaorderly Jun 28, 2026
a7c2098
fix: 좀 더 간결하게 수정
alphaorderly Jun 29, 2026
79f6f86
Merge branch 'DaleStudy:main' into main
alphaorderly Jul 4, 2026
3855235
[alphaorderly] WEEK 03 Solutions
alphaorderly Jul 4, 2026
33ab6bc
Merge branch 'main' of https://github.com/alphaorderly/leetcode-study
alphaorderly Jul 4, 2026
b1de0e1
fix: 불필요한 코드 삭제
alphaorderly Jul 4, 2026
f9bf16c
fix: 줄바꿈 린트 문제 수정
alphaorderly Jul 4, 2026
de3390f
[alphaorderly] WEEK 03 Solutions
alphaorderly Jul 4, 2026
b3dc7d7
Merge branch 'main' of https://github.com/alphaorderly/leetcode-study
alphaorderly Jul 4, 2026
17669b6
fix: 린트 오류 수정
alphaorderly Jul 4, 2026
d8b5903
fix: 파이썬 내장함수 사용 코드 추가
alphaorderly Jul 4, 2026
a14205b
fix: valid-palindrome 문제에 투포인터 구현 답안 추가
alphaorderly Jul 4, 2026
b087a32
fix: 로직 가독성 수정
alphaorderly Jul 5, 2026
2380e81
Merge branch 'DaleStudy:main' into main
alphaorderly Jul 10, 2026
e51ae37
[alphaorderly] WEEK 04 Solutions - draft
alphaorderly Jul 10, 2026
9592367
Merge branch 'main' of https://github.com/alphaorderly/leetcode-study
alphaorderly Jul 10, 2026
555e26d
fix: 코드 가독성 향상
alphaorderly Jul 11, 2026
9b11b3c
Merge branch 'DaleStudy:main' into main
alphaorderly Jul 17, 2026
aeffd8e
[alphaorderly] WEEK 05 Solutions
alphaorderly Jul 17, 2026
9fb334a
trie 사용한 풀이법 추가
alphaorderly Jul 19, 2026
cad3e9b
fix: 코드 체크 실패 개선
alphaorderly Jul 19, 2026
5d805dd
주석 개선
alphaorderly Jul 19, 2026
d64aecd
fix: 힌트 수정
alphaorderly Jul 24, 2026
f9db228
[alphaorderly] WEEK 06 Solutions
alphaorderly Jul 25, 2026
266bdae
Merge branch 'main' of https://github.com/alphaorderly/leetcode-study
alphaorderly Jul 25, 2026
bff71b4
[alphaorderly] WEEK 06 Solutions
alphaorderly Jul 27, 2026
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
33 changes: 33 additions & 0 deletions container-with-most-water/alphaorderly.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)를 활용해 낮은 높이의 벽을 더 가까이 이동시키며 면적을 최대화하는 과정을 구현하므로 Two Pointers 패턴과, 매번 더 큰 면적을 위해 더 짧은 막대를 앞으로 옮기는 결정이 탐욕적(greedy)으로 보이므로 Greedy 패턴에도 해당합니다.

📊 시간/공간 복잡도 분석

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

피드백: 좌우 포인터를 활용해 짧은 쪽의 높이가 더 큰 방향으로 이동시키며 범위를 축소해 최댓값을 갱신합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Time Complexity: O(n)
- n = number of elements in height
- Each index is visited at most once by either the left or right pointer.

Space Complexity: O(1)
- Only a small constant number of variables are used (left, right, ans).

Approach:
- Initialize two pointers at the beginning (left) and end (right) of the array.
- At each step, compute the area formed by the lines at left and right.
- Update the maximum area found so far.
- Move the pointer pointing to the shorter line inward (increase left or decrease right).
- Ensure to move shorter line inward to potentially find a taller line that could increase the area.
- Because amount of water is determined by the shorter line.
- Continue until the two pointers meet.
- Return the maximum area found.
"""
class Solution:
def maxArea(self, height: List[int]) -> int:
N = len(height)
left, right = 0, N - 1
ans = 0

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

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

return ans
85 changes: 85 additions & 0 deletions design-add-and-search-words-data-structure/alphaorderly.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, Depth-First Search, Breadth-First Search
  • 설명: 트라이(Trie) 구조를 활용해 단어 추가와 검색을 구현하고, '.' 와일드카드 처리에서 DFS 및 BFS 탐색을 사용합니다. 두 구현 모두 트리 기반 검색에 해당하며, 와일드카드 확장 시 백트래킹/분기 탐색이 포함됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(L)
Space O(T)

피드백: 글자 단위로 트라이에 노드를 생성하고 최종 노드에 end 플래그를 설정합니다. BFS로 '.' 처리 시 모든 자식 노드를 확장합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
Trie-based add and search with wildcard support.

### BFS approach ###

Time Complexity:
- addWord: O(L), where L is the length of the inserted word.
- search: O(N), where N is the length of the search word; search with '.' wildcard may lead to O(B^N) in the worst case,
where B is average branching factor. For ordinary searches (no wildcards), still O(N).

Space Complexity: O(T)
- T = total number of characters in all inserted words, due to nodes in the trie.
"""

class WordDictionary:

def __init__(self):
self.children = dict()
self.end = False

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

def search(self, word: str) -> bool:
search = deque([self])
for ch in word:
S = len(search)
for _ in range(S):
node = search.popleft()
if ch == '.':
for child in node.children.values():
search.append(child)
elif ch not in node.children:
continue
else:
search.append(node.children[ch])
return any(node.end for node in search)

"""
Trie-based add and recursive search with wildcard support.

### DFS approach ###

Time Complexity:
- addWord: O(L), where L is the length of the inserted word.
- search: Worst case O(B^N), where N is the length of the search word and B is average branching factor if all
positions are wildcards. Otherwise O(N) for ordinary search.

Space Complexity: O(T)
- T = total number of characters in all inserted words (trie size), plus call stack space O(N) during search.
"""

class WordDictionary:

def __init__(self):
self.children = dict()
self.end = False

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

def search(self, word: str) -> bool:
def dfs(node: WordDictionary, index: int) -> bool:
if index == len(word):
return node.end
ch = word[index]
if ch == ".":
for child in node.children.values():
if dfs(child, index + 1):
return True
elif ch in node.children:
return dfs(node.children[ch], index + 1)
return False

return dfs(self, 0)
23 changes: 23 additions & 0 deletions longest-increasing-subsequence/alphaorderly.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의 길이를 찾기 위해 이분탐색으로 맥락상 수열의 순서를 유지하며 최적의 끝값을 갱신합니다. 이는 열거된 DP의 최적화 형태로, 각 단계에서 이분탐색으로 위치를 찾고 배열을 갱신하는 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 수열의 최소 가능한 꼬리 값을 유지해 LIS 길이를 얻습니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Time Complexity: O(n log n)
Space Complexity: O(n)

### Binary search approach ###

For each number in nums:
- Find the insertion position for num in arr to maintain sorted order (binary search).
- If num is greater than all elements in arr, append it (extend the LIS).
- Otherwise, replace the element at position with num to keep tails as small as possible.
"""
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
arr = []

for num in nums:
position = bisect_left(arr, num)
if position == len(arr):
arr.append(num)
else:
arr[position] = num

return len(arr)
38 changes: 38 additions & 0 deletions spiral-matrix/alphaorderly.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, Backtracking, Greedy, Dynamic Programming, Monotonic Stack, Hash Map / Hash Set, Binary Search, Divide and Conquer, Union Find, Trie, Bit Manipulation
  • 설명: 코드는 매트릭스의 경계 순회(나선형 순회)를 구현하는데, 현재 위치와 방향을 유지하며 방문 여부를 표시해 다음 위치를 결정한다. 인접 방향으로의 전환과 경계 체크를 반복하는 방식은 두 포인터/슬라이딩 윈도우 느낌의 순회 로ジック에 가깝다.

📊 시간/공간 복잡도 분석

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

피드백: 방향 벡터를 따라 조건에 맞춰 방문 여부를 관리하고 결과 배열에 누적합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Spiral traversal of a matrix: visit all elements in "spiral order" (clockwise from top-left).

Time Complexity: O(N), where N is the total number of elements in matrix.
- Each element is visited once.

Space Complexity: O(N)
- The output array includes all N elements.
- The input matrix is modified in-place to mark visited cells.
"""
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
ROW = len(matrix)
COL = len(matrix[0])
TARGET = ROW * COL
DIR = [[0, 1], [1, 0], [0, -1], [-1, 0]]
CHECK = -1000

ans = []

def bound(r: int, c: int) -> bool:
return 0 <= r < ROW and 0 <= c < COL

r = c = d = 0

for _ in range(TARGET):
ans.append(matrix[r][c])
matrix[r][c] = CHECK

tr = r + DIR[d][0]
tc = c + DIR[d][1]
if not bound(tr, tc) or matrix[tr][tc] == CHECK:
d = (d + 1) % 4
r += DIR[d][0]
c += DIR[d][1]


return ans
30 changes: 30 additions & 0 deletions valid-parentheses/alphaorderly.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, Hash Map / Hash Set, Greedy, Two Pointers
  • 설명: 스택을 이용해 괄호의 짝을 맞추는 방식으로, 여는 괄호를 스택에 PUSH하고 닫는 괄호를 만날 때 스택의 맨 위와 매칭 여부를 확인하는 전형적인 스택 패턴입니다. 해시맵은 쌍을 빠르게 매칭하는 데 사용되며, 시간 복잡도는 O(n)이고 공간 복잡도는 O(n)입니다.

📊 시간/공간 복잡도 분석

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

피드백: 여는 괄호를 스택에 push하고 닫는 괄호가 올 때 매칭 여부를 확인합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Time Complexity: O(n)
- Each character in the input string s is visited exactly once in a single left-to-right scan.
- Each push or pop operation on the stack corresponds to a character, for at most O(n) stack operations.

Space Complexity: O(n)
- In the worst case (e.g., all opening brackets), the stack may contain up to n elements.
- The auxiliary data structure (`pairs`) uses constant space, as there are only three types of parentheses.

Approach:
The algorithm uses a stack to simulate balancing of brackets.
- For every opening bracket encountered, push it onto the stack.
- For every closing bracket, check if the top of the stack holds its matching opening bracket.
- If not, or if the stack is empty, the string is invalid.
- At the end, if the stack is empty, all open brackets were matched and closed properly.
"""
class Solution:
def isValid(self, s: str) -> bool:
pairs = {"(": ")", "{": "}", "[": "]"}
stack = []

for ch in s:
if ch in pairs:
stack.append(ch)
elif not stack or pairs[stack[-1]] != ch:
return False
else:
stack.pop()

return len(stack) == 0
Loading