Skip to content

Commit 70075ac

Browse files
committed
added Find Minimum in Rotated Sorted Array (Medium)
1 parent a47b7b5 commit 70075ac

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# Find Minimum in Rotated Sorted Array
3+
[Leetcode Link](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)
4+
5+
## Problem:
6+
7+
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
8+
9+
(i.e., `[0,1,2,4,5,6,7]` might become `[4,5,6,7,0,1,2]`).
10+
11+
Find the minimum element.
12+
13+
You may assume no duplicate exists in the array.
14+
15+
## Example:
16+
17+
```
18+
Input: [3,4,5,1,2]
19+
Output: 1
20+
```
21+
```
22+
Input: [4,5,6,7,0,1,2]
23+
Output: 0
24+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List
2+
3+
class Solution:
4+
def findMin(self, nums: List[int]) -> int:
5+
for i in range(len(nums)):
6+
j = i+1 if i < len(nums)-1 else 0
7+
if nums[i] >= nums[j]:
8+
return nums[j]
9+
10+
11+
12+
# test driver
13+
sol = Solution()
14+
nums = [3,4,5,1,2]
15+
print("Input:", nums)
16+
print("Output:", sol.findMin(nums))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Languages used: Java and Python
6969
- [Surrounded Regions](Medium/SurroundedRegions)
7070
- [Predict the Winner](Medium/PredictWinner)
7171
- [Subarray Sum Equals K](Medium/SubarraySumEqualsK)
72+
- [Find Minimum in Rotated Sorted Array](Medium/FindMinInRotatedSortedArray)
7273
- Hard
7374
- [Maximum Score Words Formed by Letters](Hard/MaximumScoreWords)
7475
- [Reducing Dishes](Hard/ReducingDishes)

0 commit comments

Comments
 (0)