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
19 changes: 19 additions & 0 deletions longest-substring-without-repeating-characters/tedkimdev.go
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
  • 설명: 이 코드는 연속된 부분 문자열을 찾기 위해 슬라이딩 윈도우 기법을 사용하며, 문자 위치 추적을 위해 해시 맵을 활용합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TC: O(n)
// SC: O(m)
func lengthOfLongestSubstring(s string) int {
charIndex := map[byte]int{}

maxLen := 0
left := 0
for right := 0; right < len(s); right++ {
if idx, ok := charIndex[s[right]]; ok && idx >= left {
left = idx + 1
}
charIndex[s[right]] = right
if right-left+1 > maxLen {
maxLen = right - left + 1
}
}

return maxLen
}
31 changes: 31 additions & 0 deletions number-of-islands/tedkimdev.go
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 이 코드는 깊이 우선 탐색(DFS)을 활용하여 섬을 탐지하고 연결된 '1'들을 방문 처리하는 방식으로 문제를 해결합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// TC: O(m * n)
// SC: O(m * n)
func numIslands(grid [][]byte) int {
rows, cols := len(grid), len(grid[0])
islands := 0

var dfs func(r, c int)
dfs = func(r, c int) {
if r < 0 || c < 0 ||
r >= rows || c >= cols ||
grid[r][c] == '0' {
return
}
grid[r][c] = '0'
dfs(r+1, c)
dfs(r-1, c)
dfs(r, c+1)
dfs(r, c-1)
}

for r := 0; r < rows; r++ {
for c := 0; c < cols; c++ {
if grid[r][c] == '1' {
dfs(r, c)
islands++
}
}
}

return islands
}
22 changes: 22 additions & 0 deletions reverse-linked-list/tedkimdev.go
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Iterative
  • 설명: 이 코드는 연결 리스트를 역순으로 뒤집기 위해 반복문을 사용하여 노드의 포인터를 차례로 변경하는 방식으로 구현되어 있습니다. 일반적으로 'Two Pointers' 또는 'Iterative' 패턴에 속할 수 있지만, 명확한 패턴 이름이 명시되어 있지 않아 'Iterative'로 표기하였습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/

// TC: O(n)
// SC: O(1)
func reverseList(head *ListNode) *ListNode {
var prev *ListNode
cur := head

for cur != nil {
temp := cur.Next
cur.Next = prev
prev = cur
cur = temp
}
return prev
}
40 changes: 40 additions & 0 deletions set-matrix-zeroes/tedkimdev.go
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
  • 설명: 이 코드는 행과 열을 동시에 순회하며 조건에 따라 값을 변경하는데, 두 포인터 방식으로 인덱스를 조작하는 패턴이 활용됩니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// TC: O(m * n)
// SC: O(1)
func setZeroes(matrix [][]int) {
rowNum, colNum := len(matrix), len(matrix[0])

firstRowIsZero := false

for r := 0; r < rowNum; r++ {
for c := 0; c < colNum; c++ {
if matrix[r][c] == 0 {
matrix[0][c] = 0
if r > 0 {
matrix[r][0] = 0
} else {
firstRowIsZero = true
}
}
}
}

for r := 1; r < rowNum; r++ {
for c := 1; c < colNum; c++ {
if matrix[r][0] == 0 || matrix[0][c] == 0 {
matrix[r][c] = 0
}
}
}

if matrix[0][0] == 0 { // first column is zero
for r := 0; r < rowNum; r++ {
matrix[r][0] = 0
}
}

if firstRowIsZero {
for c := 0; c < colNum; c++ {
matrix[0][c] = 0
}
}
}
17 changes: 17 additions & 0 deletions unique-paths/tedkimdev.go
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
  • 설명: 이 코드는 2차원 DP 테이블을 이용하여 경로 수를 계산하는 방식으로, 이전 상태를 기반으로 최적 해를 구하는 DP 패턴에 속합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// TC: O(m * n)
// SC: O(m * n)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 행의 계산이 바로 아래 행에만 의존하므로, 일차원 배열로 최적화하면 O(n) 공간으로 줄일 수 있을 것 같습니다.

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.

그렇네요! 감사합니다. 다음에 시도해보겠습니다.

func uniquePaths(m int, n int) int {
dp := make([][]int, m+1)
for i := range dp {
dp[i] = make([]int, n+1)
}
dp[m-1][n-1] = 1

for i := m - 1; i >= 0; i-- {
for j := n - 1; j >= 0; j-- {
dp[i][j] += dp[i+1][j] + dp[i][j+1]
}
}

return dp[0][0]
}
Loading