Search in Rotated Sorted Array

分段有序的数组,二分查找返回下标,没有返回-1

数组有序之后经过 rotated, 比如:6 1 2 3 4 5  or 5 6 7 8 1 2

思路是:

(1)nums[m] == target  return m

(2)必定有一段是有序的,找到有序段:

// m to r is ordered

   if(nums[m] < nums[r]){

             if nums[m] <= targe <= nums[r] , then l = m + 1;

      else: r = m - 1

//   l to m is ordered

  else

             if nums[l] <= targe <= nums[m] , then  r = m - 1  

      else left = m + 1;

【LeetCode 33】Search in Rotated Sorted Array的更多相关文章

  1. 【LeetCode】Search in Rotated Sorted Array II(转)

    原文链接 http://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ http://blog.csdn.net/linhuan ...

  2. 【leetcode】Search in Rotated Sorted Array II

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

  3. 【leetcode】Search in Rotated Sorted Array

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

  4. 【leetcode】Search in Rotated Sorted Array II(middle)☆

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

  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 OJ: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 & Search for a Range & Valid Sudoku

    1. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated(轮流,循环) at so ...

  8. leetcode 题解:Search in Rotated Sorted Array II (旋转已排序数组查找2)

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

  9. leetcode 二分查找 Search in Rotated Sorted Array

    Search in Rotated Sorted Array Total Accepted: 28132 Total Submissions: 98526My Submissions Suppose ...

随机推荐

  1. POJ-2240 -Arbitrage(Bellman)

    题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...

  2. DosBox 报错 this program requires dosxnt.exe to be in your path

    也就是少了dosxnt.exe文件,能够上网搜索下载,把dosxnt 拷贝到你挂截文件夹下就能够执行 Dosxnt文件下载

  3. 【Mongodb教程 第十五课 】MongoDB 限制记录

    Limit() 方法 要限制 MongoDB 中的记录,需要使用 limit() 方法. limit() 方法接受一个数字型的参数,这是要显示的文档数. 语法: limit() 方法的基本语法如下 & ...

  4. 【Mongodb教程 第十四课 】MongoDB 投影

    mongodb 投影意思是只选择必要的数据而不是选择一个文件的数据的整个.如果一个文档有5个字段,需要显示只有3个,然后选择其中只有3个字段. find() 方法 MongoDB 的find()方法, ...

  5. LoadRunner压测时,出现的问题汇总

    [问题]Error -10776  Failed to find .cfg file 错误分析:在loadrunner打开脚本的情况下,运行磁盘清理工具,导致运行打开的脚本时,提示Mdrv error ...

  6. Linux环境搭建:1. 安装VMware

    我家淘宝店,主要协助同学做毕业设计:https://shop104550034.taobao.com/?spm=2013.1.1000126.d21.pPCzDZ 1. 下载VMware 能够到我的3 ...

  7. Lightoj 1017 - Brush (III)

    1017 - Brush (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...

  8. 动态点分治入门 ZJOI2007 捉迷藏

    传送门 这道题好神奇啊……如果要是不带修改的话那就是普通的点分治了,每次维护子树中距离次大值和最大值去更新. 不过这题要修改,而且还改500000次,总不能每改一次都点分治一次吧. 所以我们来认识一个 ...

  9. java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId

    运行spring报了这个错误,网上说是spring版本冲突,检查maven依赖,发现我依赖的是spring-core.3.0.5,但是spring-orm和spring-tx依赖了spring-bea ...

  10. SpringMVC数据绑定四(自定义的类型转换器)

    1.PropertyEditor 继承PropertyEditorSupport //controller @Controller public class TestController extend ...