Skip to content

Commit 1acb347

Browse files
committed
feat: find-minimum-in-rotated-sorted-array
1 parent 12e25a1 commit 1acb347

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* <a href="https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/">find-minimum-in-rotated-sorted-array</a>
3+
* <li>Description: Given the sorted rotated array nums of unique elements, return the minimum element of this array</li>
4+
* <li>Topics: Array, Binary Search</li>
5+
* <li>Time Complexity: O(logN), Runtime 0ms</li>
6+
* <li>Space Complexity: O(1), Memory 41.78MB</li>
7+
*/
8+
9+
class Solution {
10+
public int findMin(int[] nums) {
11+
if (nums[0] <= nums[nums.length - 1]) {
12+
return nums[0];
13+
}
14+
15+
int left = 0, right = nums.length - 1;
16+
while (left < right) {
17+
int mid = (left + right + 1) / 2;
18+
if (nums[left] < nums[mid]) {
19+
left = mid;
20+
} else {
21+
right = mid - 1;
22+
}
23+
}
24+
25+
return nums[left + 1];
26+
}
27+
}

0 commit comments

Comments
 (0)