Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
4a6924f
[alphaorderly] WEEK 06 Solutions
alphaorderly Jul 30, 2026
054781c
[alphaorderly] WEEK 07 Solutions
alphaorderly Aug 2, 2026
4e6a737
Merge branch 'DaleStudy:main' into main
alphaorderly Aug 2, 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
26 changes: 26 additions & 0 deletions longest-substring-without-repeating-characters/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sliding Window, Hash Map / Hash Set
  • 설명: 문자열을 두 포인터로 서로 다른 부분 문자열을 윈도로 삼아 길이를 확장/축소하며 중복 문자를 해소하는 Sliding Window 패턴으로 구현되었고, 현재 윈도우 내 문자 빈도는 Hash Map으로 관리합니다.

📊 시간/공간 복잡도 분석

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

피드백: 해당 코드는 문자 등장 횟수를 카운트하는 해시맵을 사용해 중복 여부를 확인하고, 왼쪽 포인터를 이동시키며 윈도우를 유지합니다.

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

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

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

Approach:
- Use a defaultdict to track the count of each character in the current window.
- Maintain two pointers, 'left' and 'right', to represent the sliding window over the string.
- As we iterate over the string with 'right', increment the count for the current character.
- If a duplicate character appears in the window (count > 1), move the 'left' pointer forward and decrement counts until there are no duplicates.
- After adjusting, update 'ans' with the maximum length found for a window with all unique characters.
"""
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
count = defaultdict(int)
ans = left = 0

for right, val in enumerate(s):
count[val] += 1

while count[val] > 1:
count[s[left]] -= 1
left += 1

ans = max(ans, right - left + 1)

return ans
87 changes: 87 additions & 0 deletions number-of-islands/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Breadth-First Search
  • 설명: 주어진 코드에서 DFS(재귀를 이용한 탐색)와 BFS(큐를 이용한 탐색)로 0/1 격자에서 연결된 땅을 방문해 섬의 개수를 세는 방식이 각각 구현되어 있습니다.

📊 시간/공간 복잡도 분석

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

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

피드백: BFS 구현은 큐를 사용하여 인접한 땅을 순차적으로 방문하며 방문 표시를 남깁니다.

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

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

피드백: DFS 재귀를 사용해 연결된 영역을 탐색하고 방문한 곳은 '#'으로 표시합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
Time Complexity: O(m * n)
Space Complexity: O(m * n)
### BFS Approach ###
Approach:
- Use BFS to traverse all parts of each island in the grid.
- Employ a queue to process all adjacent land cells iteratively.
- Use a 'bound' helper function to check if a cell is within the grid bounds.
- In 'island_marker', mark visited '1's with '#' to avoid revisiting.
- For every cell in the grid, when a land cell ('1') is encountered, initiate BFS and increment the island count.
"""
class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
DIR = [[0, 1], [1, 0], [-1, 0], [0, -1]]
ROW = len(grid)
COL = len(grid[0])

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

def island_marker(row: int, col: int) -> None:
q = deque([(row, col)])
grid[row][col] = "#"

while q:
r, c = q.popleft()

for dr, dc in DIR:
tr, tc = r + dr, c + dc

if not bound(tr, tc) or grid[tr][tc] != "1":
continue

grid[tr][tc] = "#"
q.append((tr, tc))

ans = 0

for r in range(ROW):
for c in range(COL):
if grid[r][c] == "1":
island_marker(r, c)
ans += 1

return ans

"""
Time Complexity: O(m * n)
Space Complexity: O(m * n)
### DFS Approach ###
Approach:
- Use DFS to traverse all parts of each island in the grid.
- Visitation is done recursively rather than with a stack, so stack comment is removed for clarity.
- Use a 'bound' helper function to check if a cell is within the grid bounds.
- In 'island_marker', mark visited '1's with '#' to avoid revisiting.
- For every cell in the grid, when a land cell ('1') is encountered, initiate DFS and increment the island count.
"""
class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
DIR = [[0, 1], [1, 0], [-1, 0], [0, -1]]
ROW = len(grid)
COL = len(grid[0])

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

def island_marker(row: int, col: int) -> None:
grid[row][col] = '#'

for dr, dc in DIR:
tr, tc = row + dr, col + dc
if bound(tr, tc) and grid[tr][tc] == '1':
island_marker(tr, tc)

ans = 0

for r in range(ROW):
for c in range(COL):
if grid[r][c] == "1":
island_marker(r, c)
ans += 1

return ans
25 changes: 25 additions & 0 deletions reverse-linked-list/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, Linked List
  • 설명: head와 prev를 이용한 노드 포인터 재배열로 연결리스트를 역순으로 만듦. 하나의 반복에서 현재 노드의 연결 정보를 교환하며 순회하는 방식으로 O(n) 시간, O(1) 추가 공간을 달성한다.

📊 시간/공간 복잡도 분석

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

피드백: 세 개의 포인터를 교환하는 루프를 통해 노드를 역순으로 연결합니다.

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

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

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

- We use a while loop to traverse the linked list.
- We use a prev pointer to store the previous node.
- We use a head pointer to store the current node.
- We use a old_next pointer to store the next node.
- We use a prev, head = head, old_next to update the prev and head pointers.
- We return the prev pointer.
"""

class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next

class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
prev = None

while head:
prev, head.next, head = head, prev, head.next

return prev
37 changes: 37 additions & 0 deletions set-matrix-zeroes/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Dynamic Programming, Hash Map / Hash Set, Two Pointers, Sliding Window, Backtracking, Depth-First Search (DFS), Breadth-First Search (BFS), Divide and Conquer, Union Find, Trie, Bit Manipulation, Heap / Priority Queue, Monotonic Stack, Binary Search, Dynamic Programming
  • 설명: 주어진 코드는 추가 공간 없이 행과 열의 표시를 첫 행/열에 저장해 0으로 설정할 위치를 표시하는 아이디어를 사용합니다. 이것은 공간 최적화를 위한 상태 표시 패턴으로 분류되며, 문제의 목표를 만족시키기 위해 표를 두 번 순회하는 구조로 동작합니다.

📊 시간/공간 복잡도 분석

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

피드백: 첫 행/열 마커를 이용해 추가 공간 없이 제로화를 처리합니다.

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

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

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

Approach:
- Use the first row and first column as markers to track which rows and columns should be zeroed.
- First, check if the original first row or first column should be zeroed by scanning them separately.
- Then, scan the rest of the matrix. If an element is zero, set its corresponding first row and first column positions to zero.
- Next, iterate through the matrix (excluding the first row and column) and set elements to zero if their corresponding first row or first column are zero.
- Finally, zero the first row and/or first column if initially flagged.
"""
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
ROW = len(matrix)
COL = len(matrix[0])

row_check = any(matrix[0][c] == 0 for c in range(COL))
col_check = any(matrix[r][0] == 0 for r in range(ROW))

for r in range(ROW):
for c in range(COL):
if matrix[r][c] == 0:
matrix[r][0] = 0
matrix[0][c] = 0

for r in range(1, ROW):
for c in range(1, COL):
if matrix[r][0] == 0 or matrix[0][c] == 0:
matrix[r][c] = 0

if row_check:
for c in range(COL):
matrix[0][c] = 0

if col_check:
for r in range(ROW):
matrix[r][0] = 0
56 changes: 56 additions & 0 deletions unique-paths/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Binary Search, Hash Map / Hash Set, Greedy, Divide and Conquer, Two Pointers, Sliding Window, Fast & Slow Pointers, BFS, DFS, Backtracking, Union Find, Trie, Bit Manipulation, Monotonic Stack, Heap / Priority Queue
  • 설명: 주어진 코드는 2D DP와 1D DP 최적화, 그리고 수학적 조합 공식을 이용한 해법으로 구성되어 있습니다. 핵심은 중복된 부분문제 해결과 순서를 합산하는 DP 패턴으로 보이며, 마지막 케이스는 조합 공식을 이용한 분할 정복의 한 형태에 해당합니다.

📊 시간/공간 복잡도 분석

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

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

피드백: 초기화와 점화식으로 모든 경로를 누적합니다. 2D DP 버전과 1D DP 버전이 함께 제시되어 있음.

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

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

피드백: 공간 복잡도를 줄인 버전으로 동일한 시간 복잡도를 가집니다.

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

풀이 3: Solution.uniquePaths — Time: O(m + n) / Space: O(1)
복잡도
Time O(m + n)
Space O(1)

피드백: 경로의 수를 조합으로 계산하는 방법으로 상수 공간에서 빠른 해를 제공합니다.

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

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

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.

2D DP에서 dp 내용을 출력하고
대각선으로 보면 Pascal Triangle이 만들어집니다.
이것대로 Combination 연산으로 하셔도 맨 아래 코드를 얻을수 있으세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Time Complexity: O(m * n)
Space Complexity: O(m * n)
Dynamic Programming (2D DP approach):
- Use a 2D array where maze[i][j] represents the number of unique paths to cell (i, j).
- Initialize the first row and first column with 1 (since there's only one way to reach each cell: only right moves for the first row or only down moves for the first column).
- For all other cells, maze[i][j] = maze[i-1][j] + maze[i][j-1] (sum of paths from the cell above and the cell to the left).
- Return maze[m-1][n-1] as the answer, which is the total number of unique paths.
"""
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
maze = [[0 for _ in range(n)] for _ in range(m)]

for i in range(m):
for j in range(n):
if i == 0 or j == 0:
maze[i][j] = 1
else:
maze[i][j] = maze[i-1][j] + maze[i][j-1]

return maze[m-1][n-1]

"""
Time Complexity: O(m * n)
Space Complexity: O(n)
Dynamic Programming (1D DP optimization):
- Use a 1D array dp of size n.
- dp[c] keeps track of the number of unique paths to column c in the current row.
- Initialize dp with 1s (the first row has only one way to reach each column).
- For every row from the second onward, update dp[c] = dp[c] + dp[c - 1] (add ways from the left neighbor to ways accumulated so far).
- Return dp[-1] as the answer, representing the number of unique paths to the bottom-right cell.
"""
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [1] * n

for _ in range(1, m):
for c in range(1, n):
dp[c] += dp[c - 1]

return dp[-1]

"""
Time Complexity: O(m + n)
Space Complexity: O(1)
Combinatorial approach:
- The problem reduces to choosing (m-1) moves down from (m+n-2) total movements (or equivalently (n-1) moves right).
- The number of unique paths is given by the formula (m+n-2)! / [(m-1)! * (n-1)!], representing all possible orderings of down and right moves.
- Use the combinatorial (factorial) formula to compute the result efficiently.
"""
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
return comb(m + n - 2, n - 1)
Loading