Find Minimum in Rotated Sorted Array II
Description
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
public class Solution {
/**
* @param nums: a rotated sorted array
* @return: the minimum number in the array
*/
public int findMin(int[] nums) {
// write your code here
int start = Integer.MAX_VALUE , end = nums.length - 1 ;
for(int i = 0 ; i <= end ; i++){
if(nums[i] < start){
start = nums[i] ;
}
}
return start ;
}
}
本文介绍了一种解决FindMinimuminRotatedSortedArrayII问题的方法,即在一个未知旋转点的有序数组中查找最小元素。通过遍历数组并记录最小值的方式实现。此方法简单直观,易于理解。
364

被折叠的 条评论
为什么被折叠?



