Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the array.

  

class Solution {
public:
bool search(int A[], int n, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(A == NULL || n <) return false; int left = ;
int right = n-;
while(left <= right){ int mid = (right - left)/ + left;
if(A[mid] == target)
return true;
if(A[mid] > A[left])
{
if(target >= A[left] && target < A[mid])
right = mid - ;
else
left = mid + ;
}else if(A[mid] < A[left]){ if(target <= A[right] && target > A[mid])
left = mid + ;
else
right = mid -;
}else{
if(A[left] == target)
return true; ++left ;
}
}
return false;
}
};

leetcode_Search in Rotated Sorted Array II的更多相关文章

  1. 【leetcode】Search in Rotated Sorted Array II

    Search in Rotated Sorted Array II Follow up for "Search in Rotated Sorted Array":What if d ...

  2. 49. Search in Rotated Sorted Array && Search in Rotated Sorted Array II

    Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...

  3. Java for LeetCode 154 Find Minimum in Rotated Sorted Array II

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  4. [OJ] Find Minimum in Rotated Sorted Array II

    LintCode 160. Find Minimum in Rotated Sorted Array II (Medium) LeetCode 154. Find Minimum in Rotated ...

  5. LeetCode 81 Search in Rotated Sorted Array II [binary search] <c++>

    LeetCode 81 Search in Rotated Sorted Array II [binary search] <c++> 给出排序好的一维有重复元素的数组,随机取一个位置断开 ...

  6. leetcode 153. Find Minimum in Rotated Sorted Array 、154. Find Minimum in Rotated Sorted Array II 、33. Search in Rotated Sorted Array 、81. Search in Rotated Sorted Array II 、704. Binary Search

    这4个题都是针对旋转的排序数组.其中153.154是在旋转的排序数组中找最小值,33.81是在旋转的排序数组中找一个固定的值.且153和33都是没有重复数值的数组,154.81都是针对各自问题的版本1 ...

  7. 33. Search in Rotated Sorted Array & 81. Search in Rotated Sorted Array II

    33. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some piv ...

  8. LeetCode: Search in Rotated Sorted Array II 解题报告

    Search in Rotated Sorted Array II Follow up for "LeetCode: Search in Rotated Sorted Array 解题报告& ...

  9. 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)

    Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array&quo ...

随机推荐

  1. openwrt上wifi探针的实现

    openwrt上wifi探针的实现 探针是通过wifi搜集经过这个AP范围的手机的mac地址,没有什么深刻的东西,知乎上关于这个东西讨论的很多,有人觉得很有用,可以做很多增值的应用,有人觉得没啥用,不 ...

  2. 【转】Everything中文绿色版在Win7/8用不了?

    原文网址:http://pcedu.pconline.com.cn/472/4727542.html 用过Everything的朋友应该都知道,Everything有两个版本,一个是安装版,另一个是E ...

  3. js点击按钮,放大对应图片代码

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. [C++]memcpy 小记

    #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char a = ...

  5. iOS语音识别,语音播报,文字变语音播报,语音变文字

    首先使用的是科大讯飞的sdk 1.语音识别部分 AppDelegate.m #import "AppDelegate.h" #import <iflyMSC/iflyMSC. ...

  6. Redis哨兵模式

    Redis-Sentinel redis的哨兵模式 Redis Sentinel 模式简介 Redis-Sentinel是官方推荐的高可用解决方案,当redis在做master-slave的高可用方案 ...

  7. [实战]挖掘CSRF姿势

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  8. SUBTOTAL 函数与所在行

    SUBTOTAL 函数与所在行 设计要点:数据汇总.隐藏.筛选 阿金:给你推荐一个函数SUBTOTAL. 秀秀:又是函数!俺不喜欢. 阿金:虽然你不喜欢函数,但是你也离不了啊,比如汇总. 秀秀:那倒是 ...

  9. expect spawn、linux expect 用法小记

    使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: ######## ...

  10. FoxOne---一个快速高效的BS框架--(2)

    FoxOne---一个快速高效的BS框架--(1) FoxOne---一个快速高效的BS框架--(2) FoxOne---一个快速高效的BS框架--(3) FoxOne---一个快速高效的BS框架-- ...