剑指offer--面试题11:旋转数组的最小数字
来源:互联网 发布:淘宝300解id锁可以退款 编辑:程序博客网 时间:2024/06/07 17:55
#include<stdio.h>#include<iostream>using namespace std;int MinInOrder(int *a,int low,int high){int result=a[low];for(int i=low+1;i<=high&&a[i]<result;++i)result=a[i];return result;}int Min(int *a,int length){if(a==NULL||length<=0)throw new std::exception("Invalid parameters");for(int low=0,high=length-1,mid=low;a[low]>=a[high];){if(high-low==1)return a[high];mid=(low+high)/2;if(a[low]==a[high]&&a[mid]==a[low])return MinInOrder(a,low,high);if(a[mid]>=a[low])low=mid;if(a[mid]<=a[high])high=mid;}}void main(){int a[6]={3,4,5,6,1,2};printf("旋转数组{3,4,5,6,1,2}的最小数字是:%d\n",Min(a,6));int b[7]={1,2,0,1,1,1,1};printf("旋转数组{1,2,0,1,1,1,1}的最小数字是:%d\n",Min(b,6));printf("空指针测试:%d\n",Min(NULL,0));}
阅读全文
0 0
- 【剑指offer】面试题 11:旋转数组的最小数字
- 剑指offer--面试题11:旋转数组的最小数字
- 【剑指offer】面试题11:旋转数组的最小数字
- 【剑指offer】面试题8:旋转数组的最小数字
- 剑指offer面试题8:旋转数组的最小数字
- 剑指Offer:面试题8 :旋转数组的最小数字
- 《剑指offer》面试题8旋转数组的最小数字
- 《剑指Offer》之面试题旋转数组的最小数字
- 《剑指Offer》面试题8:旋转数组的最小数字
- 【剑指offer】 面试题8: 旋转数组的最小数字
- 《剑指Offer》面试题:旋转数组的最小数字
- 剑指offer面试题八:旋转数组的最小数字
- 旋转数组的最小数字(剑指offer面试题)
- 剑指offer-面试题8:旋转数组的最小数字
- 剑指offer-面试题8.旋转数组的最小数字
- 剑指offer面试题 旋转数组的最小数字
- 剑指offer面试题8:旋转数组的最小数字
- 【剑指offer】面试题8:旋转数组的最小数字
- Win32_Printer class 从WMI取到的打印机的属性信息,这一定是你想要找的 The Win32_Printer WMI class represents a device conne
- Python中import语句的使用教程
- 记录在windows10上安装FensorFlow1.2
- TortoiseSVN_32/64 包含中文补丁
- 堆排序
- 剑指offer--面试题11:旋转数组的最小数字
- 关于html中的doctype声明
- null和undefined的区别?
- mwget 多线程版本wget下载工具
- Android 笔记(个人总结)
- ThinkPHP3.2 --- 中文乱码问题
- Python 遍历文件夹中的文件,并将文件放到列表中
- java中钩子方法简单使用
- 二语句法复杂度分析器L2SCA的使用,下载,指标