We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1c0d686 commit 7aae874Copy full SHA for 7aae874
find_minimum_in_rotated_sorted_array.py
@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ # @param num: a rotated sorted array
5
+ # @return: the minimum number in the array
6
+ def findMin(self, num):
7
+ # write your code here
8
+ if len(num) == 1:
9
+ return num[0]
10
+ low = 1
11
+ high = len(num) - 1
12
+ while low < high:
13
+ mid = (low + high) / 2
14
+ if (num[mid] < num[mid - 1]) and (num[mid] < num[mid + 1]):
15
+ return num[mid]
16
+ elif num[mid] > num[0]:
17
+ low += 1
18
+ else:
19
+ high -= 1
20
+ return min(num[0], num[-1])
0 commit comments