Skip to content

[jinho] week 9 #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2025
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
14 changes: 14 additions & 0 deletions find-minimum-in-rotated-sorted-array/neverlish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 시간복잡도: O(n)
// 공간복잡도: O(1)

func findMin(nums []int) int {
result := nums[0]

for i := 1; i < len(nums)-1; i++ {
if nums[i] < nums[i-1] {
result = nums[i]
}
}
return result

}
15 changes: 15 additions & 0 deletions linked-list-cycle/neverlish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 시간복잡도: O(n)
// 공간복잡도: O(n)

func hasCycle(head *ListNode) bool {
visited := make(map[*ListNode]bool)

for head != nil {
if visited[head] {
return true
}
visited[head] = true
head = head.Next
}
return false
}
37 changes: 37 additions & 0 deletions maximum-product-subarray/neverlish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 시간복잡도: O(n)
// 공간복잡도: O(1)

func maxProduct(nums []int) int {
result, max, min := nums[0], 1, 1

for _, num := range nums {
candidates := []int{max * num, min * num, num}
max = maxIntIn3(candidates[0], candidates[1], candidates[2])
min = minIntIn3(candidates[0], candidates[1], candidates[2])
if max > result {
result = max
}
}

return result
}

func maxIntIn3(a, b, c int) int {
if a > b && a > c {
return a
}
if b > c {
return b
}
return c
}

func minIntIn3(a, b, c int) int {
if a < b && a < c {
return a
}
if b < c {
return b
}
return c
}