We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e72c709 commit 007c291Copy full SHA for 007c291
find-minimum-in-rotated-sorted-array/sonjh1217.swift
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ func findMin(_ nums: [Int]) -> Int {
3
+ var low = 1
4
+ var high = nums.count - 1
5
+
6
+ while low <= high {
7
+ let mid = (low + high) / 2
8
9
+ if nums[mid] < nums[mid - 1] {
10
+ return nums[mid]
11
+ }
12
13
+ if nums[mid] > nums[0] {
14
+ low = mid + 1
15
+ } else {
16
+ high = mid - 1
17
18
19
20
+ return nums[0]
21
22
+ //시간복잡도 O(logn)
23
+ //공간복잡도 O(1)
24
25
+}
26
0 commit comments