[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.
class Solution {
public:
bool search(int A[], int n, int target) {
if(n==) return A[]==target?true:false;
return help(A,,n-,target);
}
int help(int* & A,int l,int r,int &target)
{
if(target<A[l]&&target>A[r]) return false;
if(target==A[l]) return true;
if(target==A[r]) return true;
if(r-l==) return false;
int m = (l+r) /;
if(target==A[m]) return true;
if(A[l]<A[m]){
if(A[l]<target&&target<A[m]) return help(A,l,m,target);
return help(A,m,r,target);
}
else if(A[l]>A[m]){
if(A[m]<target&&target<A[r]) return help(A,m,r,target);
return help(A,l,m,target);
}
else{
return help(A,l,m,target)||help(A,m,r,target);
}
}
};
[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
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 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 ...
随机推荐
- thinkphp 3.2.3 程序执行时序图
- stark组件前戏(2)之单例模式
单,一个. 例,实例.对象. 通过利用Python模块导入的特性:在Python中,如果已经导入过的文件再被重新导入时候,python不会重新解释一遍,而是选择从内容中直接将原来导入的值拿来用. ...
- Codeforces Round #464 (Div. 2) C. Convenient For Everybody
C. Convenient For Everybody time limit per test2 seconds memory limit per test256 megabytes Problem ...
- [BZOJ1588]营业额统计(Splay)
Description 题意:给定 n个数,每给定一个数,在之前的数里找一个与当前数相差最小的数,求相差之和(第一个数为它本身) 如:5 1 2 5 4 6 Ans=5+|1-5|+|2-1|+|5- ...
- Java技术——Java多线程学习
)适合多个相同程序代码的线程区处理同一资源的情况.比如下面这个买票的例子. //使用Thread实现 public static class MyThread extends Thread{ priv ...
- OpenCV学习笔记(五) 文件存取
转自输入输出XML和YAML文件 To be filled
- Django admin模块使用search时报错:django.core.exceptions.FieldError: Related Field got invalid lookup: contains
日志如下: <class 'django.core.handlers.wsgi.WSGIRequest'> ------------registered_admins: {'spaceCl ...
- luogu3195 [HNOI2008]玩具装箱TOY
懒得写 #include <iostream> #include <cstdio> using namespace std; typedef long long longliv ...
- ckeditor添加日历控件
这里日历控件用的是开源的My97DatePicker,先看下效果图: 1.点击左侧自定义的日历控件按钮,弹出日历控件对话框. 2.点击确定,日历控件添加的表单设计器中,同时保留日历的控件样式 3.点击 ...
- phpMyAdmin 4.7.x CSRF
phpMyAdmin 4.7.x CSRF 场景:管理员登陆phpmyadmin之后,我试验了一下,发现只要是登陆session没有失效应该是都可以的, 利用,phpmyadmin可以通过get方式操 ...