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. Visual Studio VS如何修改代码字体

    工具-选项-环境-字体和颜色

  2. udhcp源码详解(一)之文件组织结构(dhcp server) --转

    udhcp目录下有十几个源文件,一个源文件相对应一个模块,完成一系列相关的功能,例如在static_leases.c主要针对static_lease链表增删查找等操作. dhcpd.c——   整个d ...

  3. [Sciter] 1. 创建最简单的Sciter项目

    一些函数 sciter::debug_output_console _; 程序运行时自动启动一个控制台窗口,通过在_tiscript_中调用stdout.println来输出调试信息 SciterSe ...

  4. vs2010中设置qt环境的智能识别方案

    Qt搭建请参考:Win7系统VS2010下搭建qt开发环境 搭建好之后,虽然可以编译过去,但是写代码时,编辑器无法识别,也没有智能提示,并且代码中都是红色的提示如下: 此时需要设置一下include路 ...

  5. CXF 中自定义SOAPHeader

    Interceptor是CXF架构中一个很有特色的模式.你可以在不对核心模块进行修改的情况下,动态添加很多功能.这对于CXF这个以处理消息为中心的服务框架来说是非常有用的,CXF通过在Intercep ...

  6. DataTables warning requested unknown parameter

    This is possibly the most cryptic warning message that DataTables will show. It is a short error mes ...

  7. 浅谈cookie 和session 的区别

    具体来说 cookie 是保存在“客户端”的,而session是保存在“服务端”的 cookie 是通过扩展http协议实现的 cookie 主要包括 :名字,值,过期时间,路径和域: 如果cooki ...

  8. UESTC149 解救小Q

    小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她.迷宫里面有一些陷阱,一旦走到陷阱里,就会被困身亡:(,迷宫里还有一些古老的传送阵,一旦走到传送阵上,会强制被传送到传送阵的另一头.现在请你 ...

  9. vb6转vb.net

    一直在用vb6写软件,但最近系统要做web版,但之前的业务规则全在代码中写死了,没用使用存贮过程,如果在web端重写规则,则工作量太大,项目时间也不允许,只好把业务规则转到vb.net中.现在的vb. ...

  10. Ubuntu SDL lib 安装

    /******************************************************************** * Ubuntu SDL lib 安装 * 说明: * 今天 ...