Skip to content

Commit 6a8add1

Browse files
Added Day-25 Solution
1 parent 3fc28cf commit 6a8add1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
3+
4+
(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).
5+
6+
Find the minimum element.
7+
8+
The array may contain duplicates.
9+
10+
Example 1:
11+
12+
Input: [1,3,5]
13+
Output: 1
14+
Example 2:
15+
16+
Input: [2,2,2,0,1]
17+
Output: 0
18+
Note:
19+
20+
This is a follow up problem to Find Minimum in Rotated Sorted Array.
21+
Would allow duplicates affect the run-time complexity? How and why?
22+
23+
'''
24+
25+
class Solution:
26+
def findMin(self, nums: List[int]) -> int:
27+
for i in range(len(nums)-1):
28+
if nums[i] > nums[i+1]:
29+
return nums[i+1]
30+
return nums[0]

0 commit comments

Comments
 (0)