原题链接

直接贴代码,这道题是

search in rotated sorted array leetcode

的前面部分!

 class Solution {
public:
int findMin(vector<int>& nums) {
if (nums.empty())
return -;
int res = find(nums, , nums.size()-);//好神奇,第二个参数无论减或者不减1,都不影响该题的结果
if (res == -)
return -;
return nums[res];
}
int find(vector<int>& nums, int l, int r)
{
if (l>r || l >= nums.size())
return -;
int mid = (l + r) / ;
if (nums[l] <= nums[mid])
{
int pos = find(nums, mid + , r);
if (pos == -)
return l;
return nums[l]<nums[pos] ? l : pos;
}
else
{
int pos = find(nums, l, mid - );
if (pos == -)
return mid;
return nums[mid]<nums[pos] ? mid : pos;
}
}
};

Find Minimum in Rotated Sorted Array leetcode的更多相关文章

  1. 153. Find Minimum in Rotated Sorted Array - LeetCode

    Question 153. Find Minimum in Rotated Sorted Array Solution 题目大意:给一个按增序排列的数组,其中有一段错位了[1,2,3,4,5,6]变成 ...

  2. Find Minimum in Rotated Sorted Array leetcode java

    题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...

  3. Find Minimum in Rotated Sorted Array——LeetCode

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  4. 153. Find Minimum in Rotated Sorted Array(leetcode, binary search)

    https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/ leetcode 的题目,binary ...

  5. [LeetCode] Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二

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

  6. [LeetCode] Find Minimum 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 ...

  7. 【leetcode】Find Minimum in Rotated Sorted Array I&&II

    题目概述: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 ...

  8. LeetCode Find Minimum in Rotated Sorted Array II

    原题链接在这里:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 题目: Follow up for &qu ...

  9. LeetCode Find Minimum in Rotated Sorted Array

    原题链接在这里:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Method 1 就是找到第一个违反升序的值,就 ...

随机推荐

  1. 剑指Offer:面试题28——字符串的排列(java实现)(待序)

    问题描述: 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 结果请按字母 ...

  2. autoit 中_GUICtrlStatusBar_SetBkColor失效的解决办法

    #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WinAPI.au3> #i ...

  3. 有效Email

    !/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($.trim($('#account').val()))

  4. 向mysql数据库中插入大二进制文件和大文本

    @Test      public void run() throws ClassNotFoundException, SQLException,                 FileNotFou ...

  5. .net实现调用本地exe等应用程序的办法总结

    根据客户需求用户要实现在一个BS系统上打开本地的一应用程序,在网上查了好多资料再加上自己的各种测试,到最后功能是实现了,只不过还存在一些问题,接下来会先把各种方法一一列举出来 1.先写最终测试通过的这 ...

  6. NHibernate系列文章十五:NHibernate组件

    摘要 前面文章介绍了NHibernate对简单.net数据类型的映射对照表.NHibernate也可以映射复杂数据类型,这里介绍通过组件映射NHibernate值对象. 1. NHibernate引用 ...

  7. 图片form表单提交和id提交

    <form action="${pageContext.request.contextPath }/sarchServlet" method="post" ...

  8. TJI读书笔记09-访问控制权限

    TJI读书笔记09-访问控制权限 包,package和import 权限修饰符 接口和实现 类的访问权限控制 首先问一个问题,为什么要有访问控制权限? 安全,这当然是一个很重要的原因. 让类库的使用者 ...

  9. Solr Cloud搭建

    1:搭建tomcat 配置connector: server.xm文件中: <Connector port="8080"maxThreads="200" ...

  10. Asp.net using Oracle.DataAccess.dll access oracle 11g 64bit & x86

    使用.net访问oracle数据库时一般需要在机器上安装instantclient才能正常连接. 下面介绍一种不用安装instantclient直接引用dll就用.net能连接oracle数据库的方法 ...