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. LeetCode 67 Add Binary(二进制相加)(*)

    翻译 给定两个二进制字符串,返回它们的和(也是二进制字符串). 比如, a = "11" b = "1" 返回 "100". 原文 Give ...

  2. MongoDB使用入门

    1.MongoDB的安装 步骤一:下载MongoDB 下载安装包:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz 步骤二:设置 ...

  3. 游戏server设计的一些感悟

    Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Date:September 30 ...

  4. centos 安装mysql时错误unknown variable &#39;defaults-file=/opt/redmine-2.6.0-2/mysql/my.cnf&#39;

    找到my.cnf所在目录.运行 chmod 664 my.cnf,再启动mysql成功

  5. ExtJs里表格自动显隐滚动条

    ExtJs里面,layout:'border'这种布局应该很常用,但我用的时候,因为不熟,走了一些弯路.比如说,一个页面,大体布局是这样的: 上:查询输入框 中+下:查询结果(表格,底部有分页控件) ...

  6. 2016/3/21 面向对象: ①定义类 ②实例化对象 ③$this关键字 ④构造函数 ⑤析构函数 ⑥封装 ⑦继承

    一:定义类   二:实例化对象 //定义类 class Ren { var $name; var $sex; var $age; function Say() { echo "{$this- ...

  7. 2016/2/29 html 思维导图

  8. 浏览器同部署了https的服务器交互的过程

    1 浏览器发起https请求 2 https服务器发送自己的公钥给浏览器 3 浏览器用https服务器发送过来的公钥加密一个用于双方通信的的对称密码 4 https服务器用自己的私钥解密,获取对称密码 ...

  9. high-level operations on files and collections of files

    11.10. shutil — High-level file operations — Python 3.6.5 documentation https://docs.python.org/3/li ...

  10. (ros/moveit)cob_simulation報錯

    cob_simulation報錯 依照官網說明 http://wiki.ros.org/cob_bringup_sim 1. git clone https://github.com/ipa320/c ...