154. Find Minimum in Rotated Sorted Array II
Posted warmland
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了154. Find Minimum in Rotated Sorted Array II相关的知识,希望对你有一定的参考价值。
就比1多了一点点
1 public int findMin(int[] nums) { 2 if(nums.length == 0) { 3 return -1; 4 } 5 int left = 0; 6 int right = nums.length - 1; 7 while(left < right) { 8 int mid = left + (right - left) / 2; 9 if(nums[mid] > nums[right]) { 10 left = mid + 1; 11 } else if(nums[mid] < nums[right]) { 12 right = mid; 13 } else { 14 right--; 15 } 16 } 17 return nums[left]; 18 }
第13行,当nums[mid] == nums[high]的时候high--
以上是关于154. Find Minimum in Rotated Sorted Array II的主要内容,如果未能解决你的问题,请参考以下文章
154. Find Minimum in Rotated Sorted Array II
#Leetcode# 154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array II(Binary search)