Skip to content

Commit

Permalink
add cleaner solution
Browse files Browse the repository at this point in the history
  • Loading branch information
obzva committed Oct 11, 2024
1 parent eb0c7ca commit 85d05c1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion find-minimum-in-rotated-sorted-array/flynn.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
ํ’€์ด
ํ’€์ด 1
- ์ฃผ์–ด์ง„ ๋ฐฐ์—ด์„ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด์ง„ํƒ์ƒ‰์„ ์ด์šฉํ•˜์—ฌ ํ’€์ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
์ฃผ์–ด์ง„ ๋ฐฐ์—ด์ด A = [4,5,6,7,0,1,2] ๋ผ๊ณ  ํ•  ๋•Œ, ์ด ๋ฐฐ์—ด์€ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
A[0:3] : rotate๋˜์–ด ์•ž์œผ๋กœ ๋ฐฐ์—ด์˜ ์•ž์œผ๋กœ ์˜ฎ๊ฒจ์ง„ ๋ถ€๋ถ„
Expand Down Expand Up @@ -39,3 +39,27 @@ func findMin(nums []int) int {

return nums[lo]
}

/*
ํ’€์ด 2
- ํ’€์ด 1์—์„œ ๋œ์–ด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋กœ์ง์„ ๋œ์–ด๋‚ธ ์ข€ ๋” ๊น”๋”ํ•œ ์ด์ง„ํƒ์ƒ‰ ํ’€์ด์ž…๋‹ˆ๋‹ค
Big O
- ํ’€์ด 1๊ณผ ๋™์ผ
*/

func findMin(nums []int) int {
lo, hi := 0, len(nums)

for lo < hi {
mid := lo+(hi-lo)/2

if nums[mid] > nums[len(nums)-1] {
lo = mid + 1
} else {
hi = mid
}
}

return nums[lo]
}

0 comments on commit 85d05c1

Please sign in to comment.