leetcode-Search in Rotated Sorted Array II-81

Posted 0_summer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode-Search in Rotated Sorted Array II-81相关的知识,希望对你有一定的参考价值。

这题和http://www.cnblogs.com/0summer/p/5825282.html一样,只是上一题中序列里没有重复的元素

代码都是一样的

 1 class Solution {
 2 public:
 3     bool search(vector<int>& nums, int target) {
 4         if(nums.size()==0) return false;
 5         int l=0,r=nums.size()-1;
 6         while(l<=r){
 7             int mid=(l+r)>>1;
 8             if(nums[mid]==target) return true;
 9             if(nums[l]<nums[mid]){
10                 if(nums[l]<=target&&target<=nums[mid]) r=mid-1;
11                 else l=mid+1;
12             }
13             else if(nums[l]>nums[mid]){
14                 if(target>=nums[l]||target<=nums[mid]) r=mid-1;
15                 else l=mid+1;
16             }
17             else l++;
18         }
19         return false;
20     }
21 };

 

以上是关于leetcode-Search in Rotated Sorted Array II-81的主要内容,如果未能解决你的问题,请参考以下文章

leetcode-Search in Rotated Sorted Array II-81

LeetCode-Search a 2D Matrix

leetCode-Search Insert Position

LeetCode-Search a 2D Matrix II

leetcode-Search a 2D Matrix II-240

array copy rotate in Pointwise