Skip to content

Commit c2a09aa

Browse files
committed
find minimum in rotated sorted list
1 parent eeadc80 commit c2a09aa

File tree

3 files changed

+64
-35
lines changed

3 files changed

+64
-35
lines changed

.idea/workspace.xml

Lines changed: 34 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ codes may not be optimized
396396
1. [Word Frequency](https://leetcode.com/problems/word-frequency/description/)
397397
1. [Department Highest Salary](https://leetcode.com/problems/department-highest-salary/description/)
398398
1. [Populating Next Right Pointer in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/)
399+
1. [Find Minimum in Rotated Sorted List](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.chen0040.leetcode.day18.medium;
2+
3+
4+
/**
5+
* Created by xschen on 13/8/2017.
6+
*
7+
* link: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/
8+
*/
9+
public class FindMinimumInRotatedSortedList {
10+
public class Solution {
11+
public int findMin(int[] nums) {
12+
int lo = 0;
13+
int hi = nums.length - 1;
14+
while(lo <= hi) {
15+
int mid = lo + (hi - lo) / 2;
16+
if(mid > 0 && nums[mid] < nums[mid-1]) {
17+
return nums[mid];
18+
}
19+
if(nums[lo] <= nums[mid] && nums[mid] > nums[hi]) {
20+
lo = mid + 1;
21+
} else {
22+
hi = mid - 1;
23+
}
24+
}
25+
26+
return nums[lo];
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)