File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
find-minimum-in-rotated-sorted-array Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments