We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e925819 commit bca62bdCopy full SHA for bca62bd
2 files changed
.idea/workspace.xml
Target Offer/旋转数组的最小数字.py
@@ -29,6 +29,31 @@ def minNumberInRotateArray(self, rotateArray):
29
rear = i
30
minVal = rotateArray[rear]
31
return minVal
32
+ # 书上方法
33
+ def minNumberInRotateArray2(self, rotateArray):
34
+ if len(rotateArray) == 0:
35
+ return 0
36
+ front, rear = 0, len(rotateArray) - 1
37
+ midIndex = 0
38
+ while rotateArray[front] >= rotateArray[rear]:
39
+ if rear - front == 1:
40
+ midIndex = rear
41
+ break
42
+ midIndex = (front + rear) // 2
43
+ if rotateArray[front] == rotateArray[rear] and rotateArray[front] == rotateArray[midIndex]:
44
+ return self.MinInOrder(rotateArray, front, rear)
45
+
46
+ if rotateArray[midIndex] >= rotateArray[front]:
47
+ front = midIndex
48
+ elif rotateArray[midIndex] <= rotateArray[rear]:
49
+ rear = midIndex
50
+ return rotateArray[midIndex]
51
+ def MinInOrder(self, array, front, end):
52
+ result = array[0]
53
+ for i in array[front:end+1]:
54
+ if i < result:
55
+ result = i
56
+ return result
57
58
Test = Solution()
59
print(Test.minNumberInRotateArray([3, 4, 5, 1, 2]))
0 commit comments