LeetCode——Search in Rotated Sorted Array II
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的更多相关文章
- LeetCode: Search in Rotated Sorted Array II 解题报告
Search in Rotated Sorted Array II Follow up for "LeetCode: Search in Rotated Sorted Array 解题报告& ...
- [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- [leetcode]Search in Rotated Sorted Array II @ Python
原题地址:https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ 题意: Follow up for "Sea ...
- [LeetCode] Search in Rotated Sorted Array II [36]
称号 Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would t ...
- [Leetcode] search in rotated sorted array ii 搜索旋转有序数组
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- [LeetCode] Search in Rotated Sorted Array II 二分搜索
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- LeetCode Search in Rotated Sorted Array II -- 有重复的旋转序列搜索
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- 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 ...
- LeetCode OJ:Search in Rotated Sorted Array II(翻转排序数组的查找)
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
随机推荐
- SQL注入(一)普通型注入
既然说了从头开始,先从注入开始吧,先来温习一下之前会的一些注入. PHP注入 0x01: 判断是否存在注入: ' 报错 ' and 1=1 正确 ' and 1=2 错误 0x01: or ...
- django admin manytomany获取所选字段值
和一般views中前端数据的获取一样. def save_model(self, request, obj, form, change): door_id_list= request. ...
- Effective C++_笔记_条款06_若不想使用编译器自动生成的函数,就该明确拒绝
(整理自Effctive C++,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 通常如果你不希望class支持某一特定机能,只要不声明对应函数就 ...
- VS关闭Browser Link
原文:VS关闭Browser Link 这是VS2013的一个新功能,叫Browser Link,基于SignalR. 它可以实现VS IDE和你的程序的双向通讯,在IDE编辑代码即刻将修改发送到浏览 ...
- 显示出eclipse文件层次
看到图片中右边那个倒三角型符号没, 点一下,弹出个菜单,选package presentation->hierarachial 文件目录结构 flat 是包结构
- reduce个数究竟和哪些因素有关
reduce的数目究竟和哪些因素有关 1.我们知道map的数量和文件数.文件大小.块大小.以及split大小有关,而reduce的数量跟哪些因素有关呢? 设置mapred.tasktracker.r ...
- LintCode 推断一个二叉树树是否是还有一个二叉树的子书
有两个不同大小的二进制树: T1 有上百万的节点: T2 有好几百的节点. 请设计一种算法.判定 T2 是否为 T1的子树. /** * Definition of TreeNode: * class ...
- oracle列合并
在很多场合,我们会须要用到oracle列合并,oracle提供了一些方法用于把某列的多行数据合并成一行. 一.10G曾经使用WMSYS.WM_CONCAT wmsys.wm_concat将字段的值 ...
- Windows环境下访问NFS(33篇Storage的文章)
Windows环境下访问NFS 使用Solaris时,如果想在两台Solaris之间共享数据,那么你想到的最省事.最方便的方法肯定是nfs.但是现在的学生们的桌面,估计99%以上都是Windows,W ...
- Infinite scroll has been called autopagerize, unpaginate, endless pages
http://www.infinite-scroll.com/ Infinite scroll has been called autopagerize, unpaginate, endless pa ...