File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
find-minimum-in-rotated-sorted-array Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ //๊ทธ๋ฅ ์ ๋ ฌ ํ๊ณ 0๋ฒ์งธ ์ธ๋ฑ์ค ์์ ์ถ์ถ
2+ //O(nlogn)
3+ // class Solution {
4+ // func findMin(_ nums: [Int]) -> Int {
5+ // var sortednums = nums.sorted()
6+ // return sortednums[0]
7+ // }
8+ // }
9+
10+
11+ //์ด์ง ํ์
12+ //๋ฐฐ์ด์ด ๋ค ์ ๋ ฌ์ด ๋์ด์ผ ๊ฐ๋ฅํ์ง ์๋? ํ๋๋ฐ
13+ //์ด ๋ฌธ์ ๋ 'ํ์ ๋ ์ ๋ ฌ ๋ฐฐ์ด'์ด๋ผ์ ์ด์ง ํ์์ด ๊ฐ๋ฅํ๋ค์บ.
14+ //O(logn)
15+ class Solution {
16+ func findMin( _ nums: [ Int ] ) -> Int {
17+ var left = 0
18+ var right = nums. count - 1
19+
20+ while left < right{
21+ var mid = ( left+ right) / 2
22+ if nums [ mid] > nums [ right] {
23+ left = mid + 1
24+ } else {
25+ right = mid
26+ }
27+ }
28+
29+ return nums [ left]
30+ }
31+ }
You canโt perform that action at this time.
0 commit comments