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
23 changes: 23 additions & 0 deletions linked-list-cycle/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Fast & Slow Pointers
  • 설명: 이 코드는 느린 포인터와 빠른 포인터를 이용하여 순환 여부를 판단하는 패턴으로, 순환 탐지에 적합합니다.

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.

Go를 잘 모르지만 이해가 잘 되네요 :) 고생하셨습니다!

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

// TC: O(n)
// SC: O(1)
func hasCycle(head *ListNode) bool {
slow := head
fast := head
for fast != nil && fast.Next != nil {
slow = slow.Next
fast = fast.Next.Next
if slow == fast {
return true
}
}

return false
}
55 changes: 55 additions & 0 deletions minimum-window-substring/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
  • 설명: 이 코드는 슬라이딩 윈도우 기법을 활용하여 문자열 s 내에서 t의 모든 문자들을 포함하는 최소 길이의 부분 문자열을 찾는 문제를 해결합니다. 윈도우의 크기를 조절하며 조건을 만족하는 구간을 탐색하는 방식입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// TC: O(n * m)
// SC: O(n + m)

func minWindow(s string, t string) string {
if len(t) > len(s) {
return ""
}

countT := map[byte]int{}
for i := 0; i < len(t); i++ {
countT[t[i]]++
}

windowMap := map[byte]int{}
have, need := 0, len(countT)

left := 0
resLeft, resRight := -1, -1
resLen := len(s) + 1

for right := 0; right < len(s); right++ {
c := s[right]
windowMap[c]++

// update have
if count, ok := countT[c]; ok {
if windowMap[c] == count {
have++
}
}

// window valid -> move left to find minimum
for have == need {
if right-left+1 < resLen {
resLen = right - left + 1
resLeft, resRight = left, right
}

// remove left char
lc := s[left]
if count, ok := countT[lc]; ok {
if windowMap[lc] == count {
have--
}
}
windowMap[lc]--
left++
}
}

if resLeft == -1 {
return ""
}
return s[resLeft : resRight+1]
}
Loading