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.

原题链接:https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/

题目:继续之前的题,在旋转过的有序数组中找目标值。若同意有反复的值呢?

	public boolean search(int[] A, int target) {
int low = 0, high = A.length - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (target == A[mid])
return true;
if (A[mid] > A[low]) {
if (target >= A[low] && target <= A[mid])
high = mid - 1;
else
low = mid + 1;
} else if (A[mid] < A[low]) {
if (target >= A[mid] && target <= A[high])
low = mid + 1;
else
high = mid - 1;
} else
low += 1;
}
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 "LeetCode: Search in Rotated Sorted Array 解题报告& ...

  2. [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  3. [leetcode]Search in Rotated Sorted Array II @ Python

    原题地址:https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ 题意: Follow up for "Sea ...

  4. [LeetCode] Search in Rotated Sorted Array II [36]

    称号 Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would t ...

  5. [Leetcode] search in rotated sorted array ii 搜索旋转有序数组

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  6. [LeetCode] Search in Rotated Sorted Array II 二分搜索

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  7. LeetCode Search in Rotated Sorted Array II -- 有重复的旋转序列搜索

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  8. LeetCode:Search in Rotated Sorted Array I II

    LeetCode:Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to y ...

  9. LeetCode OJ:Search in Rotated Sorted Array II(翻转排序数组的查找)

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

随机推荐

  1. POJ 1258-Agri-Net (Kruskal)

    题目链接:Agri-Net 最小生成树水题,数组开的和题目描写叙述一样,可是就是RE,有填了个0,还好这个题用 库鲁斯卡尔 敲了一遍,发现了点问题,曾经写的库鲁卡尔模板有点问题,多写了步没用的操作,已 ...

  2. ASP.NET - Eval数据绑定

    <!--新闻分类--> <div id ="category" class ="Frm"> <h4>新闻分类</h4& ...

  3. OCP-1Z0-042-V12.39-47题

    47.Which two database operations can be performed at the mount stage of database startup? 题目解析: A和E在 ...

  4. ANDROID自定义视图——onMeasure流程,MeasureSpec详解

    简介: 在自定义view的时候,其实很简单,只需要知道3步骤: 1.测量——onMeasure():决定View的大小 2.布局——onLayout():决定View在ViewGroup中的位置 3. ...

  5. Http请求工具实例编写(超长,比较清楚)

    HTTP协议工作方式首先客户端发送一个请求(request)给服务器,服务器在接收到这个请求后将生成一个响应(response)返回给客户端.在这个通信的过程中HTTP协议在以下4个方面做了规定:1. ...

  6. Spring mvc interceptor配置拦截器,没有登录跳到登录页

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. java输出空心菱形

    package com.zsh; import java.util.Scanner; public class Test08 { public static void main(String[] ar ...

  8. Swift - 导航条(UINavigationBar)的使用

    与导航控制器(UINavigationController)同时实现导航条和页面切换功能不同. 导航条(UINavgationBar)可以单独使用,添加至任何的UIView中.UINavigation ...

  9. Jexus + Kestrel 部署 asp.net core

    结合Jexus + Kestrel 部署 asp.net core 生产环境 ASP.NET Core 是微软的全新的框架.这一框架的目标 ︰ 跨平台 针对云应用优化 解除 System.Web 的依 ...

  10. [Android学习笔记]Android向下兼

    Android向下兼容的思路:使用高版本的API,在运行时判断真实运行平台的API版本,根据不同版本做不同的处理 关键类:Build.class里面定义了API版本相关信息 内部类:VERSION定义 ...