---
description: 二分查找法，条件变了
---

# leetcode33 搜索旋转排序数组

```golang
func search(nums []int, target int) int {

    left,right:=0,len(nums)-1

    for left<=right{
        mid:=(left+right)/2

        if nums[mid]==target{
            return mid
        }

        if  (nums[left]<=target && target<= nums[mid]) || (nums[mid]<=nums[right]&& (target<nums[mid] || target>nums[right]) ) {
            right=mid-1
        }else{
            left=mid+1
        }
    }
    return -1

}
```
