Leetcode81搜索旋转排序数组2

代码:

和33很像 二分查找

class Solution {
    public boolean search(int[] nums, int target) {
        int idx = 0;
        int n = nums.length;
        for(int i=1;i=nums[0]){
            l=0;
            r=idx-1;
        }else{
            l=idx;
            r=n-1;
        }
        while(l<=r){
            int m = (l+r)/2;
            if(target==nums[m]){
                return true;
            }else if(target

你可能感兴趣的:(算法,leetcode,数据结构)