【剑指offer】题8:旋转数组的最小值
来源:互联网 发布:网络系统管理课程 编辑:程序博客网 时间:2024/06/05 08:42
考虑到:
3 4 5 1 2
1 0 1 1 1
1 2 3 4 5
1
1 1 1 1
null
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <numeric>#include <iomanip>#include <stack>using namespace std;#define debug_int bin_find(vector<int>& vec, int left, int right){ while (vec[left] == vec[right] && (left + 1 < right)) { left += 1; } if (left +1 == right) return min(vec[right],vec[left]); if (vec[left] < vec[right]) return vec[left]; int mid = left + ((right - left) >> 1); if ( vec[mid] < vec[left] ) { return bin_find(vec,left, mid); } else { return bin_find(vec, mid, right); }}int minNumberInRotateArray(vector<int> rotateArray){ if (rotateArray.empty()) throw new std::exception("error parameter"); int left(0),right(rotateArray.size()-1); if (right == left) return rotateArray[left]; return bin_find(rotateArray, left, right);}int main(){ vector<int> vec; //vector<int> vec{1,2,3}; cout<<minNumberInRotateArray(vec); return 0;}
阅读全文
0 0
- Offer题8 旋转数组的最小值
- 【剑指offer】题8:旋转数组的最小值
- 【剑指offer】旋转数组的最小值
- [剑指offer]旋转数组的最小值
- 【剑指offer】旋转数组的最小值
- 【剑指offer】旋转数组的最小值
- 【剑指offer之旋转数组的最小值】
- 剑指offer -- 旋转数组最小值
- 剑指offer系列之六:旋转数组的最小值
- 剑指offer——旋转数组的最小值
- 【剑指offer】面试题8:旋转数组中的最小值
- 剑指offer 面试题8 输出旋转数组最小值
- 剑指offer之旋转数组中的最小值
- 剑指offer(5) 旋转数组中的最小值
- 剑指 offer——面试题8求旋转数组的最小值
- 剑指Offer:面试题8——旋转数组的最小值(java实现)
- 剑指offer 面试题8 旋转数组的最小值 java版答案
- 剑指offer:求一个旋转数组中的最小值
- 创业路上折腾了十多年,讲讲这些年的经历和感悟——与大家共勉
- 617. Merge Two Binary Trees
- LeetCode 120. Triangle 动态规划
- [项目实训]6.13 contest_modify html文件编写
- Spring Boot集成cache
- 【剑指offer】题8:旋转数组的最小值
- 1059. C语言竞赛(20)
- This document in intended to assist with identifying and resolving system panics related to Solaris
- 【面试二三事】安全岗面试谈关于SQL注入
- java&jsp最简单的注册数据库连接
- 数据库专家:MySQL分片水很深
- 软件工程课程总结
- 单点登录实现
- Tree(2)--二叉树(Binary Tree)