【leetcode】Search in Rotated Sorted Array II
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.
class Solution {
public:
bool search(int A[], int n, int target) { int left=;
int right=n-;
int mid;
while(left<=right)
{ mid=(left+right)/;
if(A[mid]==target)
{
return true;
} //增加了这些判断语句
bool isLeft=true; for(int i=left;i<=mid;i++)
{
if(A[i]>A[mid])
{
isLeft=false;
break;
}
} if(isLeft)
{
if(A[left]<=target&&target<A[mid])
{
right=mid-;
}
else
{
left=mid+;
}
}
else
{
if(A[mid]<target&&target<=A[right])
{
left=mid+;
}
else
{
right=mid-;
}
} }
return false; }
};
【leetcode】Search in Rotated Sorted Array II的更多相关文章
- 【LeetCode】Search in Rotated Sorted Array II(转)
原文链接 http://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ http://blog.csdn.net/linhuan ...
- 【leetcode】Search in Rotated Sorted Array II(middle)☆
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- 【leetcode】Search in Rotated Sorted Array
Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...
- 【题解】【数组】【查找】【Leetcode】Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- 【LeetCode】Search in Rotated Sorted Array——旋转有序数列找目标值
[题目] Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- 【leetcode】Search in Rotated Sorted Array (hard)
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- LeetCode 81 Search in Rotated Sorted Array II [binary search] <c++>
LeetCode 81 Search in Rotated Sorted Array II [binary search] <c++> 给出排序好的一维有重复元素的数组,随机取一个位置断开 ...
- [leetcode]81. Search in Rotated Sorted Array II旋转过有序数组里找目标值II(有重)
This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates. 思路 ...
- Java for LeetCode 081 Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this ...
随机推荐
- Yii2.0-生成二维码实例
原文地址:http://www.yii-china.com/post/detail/19.html
- 安装CentOS7重启后提示License information
Initial setup of CentOS Linux (core) ) [x] Creat user ) [!] License information (no user will be cre ...
- Spring--Spring容器
在使用Spring所提供的各种丰富而神奇的功能之前,必须要在Spring IoC容器中装配好Bean,并建立Bean和Bean之间的关联关系. Spring提供了多种配置方式来实现Bean的装配.但在 ...
- Python开发【第十七篇】:MySQL(一)
一.概述 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL Serve ...
- QT入门
QT += core gui widgets //引入需要用到的库 qDebug()<<"t="<<t<<QTime::currentTime( ...
- MySQL5.7 Replication主从复制配置教程
最近配置mysql5.7主从复制的时候碰到了些问题,老老实实按老版本的步骤配置会有错误,后来自己查看了官方文档,才解决了问题,在这里总结一下5.7的配置步骤, 大体步骤跟老版本的还是一样的,只是有一些 ...
- Unity API
关于 int Mathf.PingPong(t, length); 原理,相当于 #include <iostream> #include <vector> int test( ...
- 知识梳理HTML篇
HTML 浏览器内核: IE:trident Firefox : gecko Safari/chrome : webkit Opera : presto(新 ...
- AngularJS API之isXXX()
Angular中保存了很多的判断方法,可以用来验证对象是否符合某种要求,详细的参考代码样例即可 <html> <head> <meta http-equiv=" ...
- ggplot2 上篇
title: "ggplot2 上篇" author: "li_volleyball" date: "2016年4月16日" output: ...