博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode – Refresh – Find Minimum in Rotated Array II
阅读量:7239 次
发布时间:2019-06-29

本文共 730 字,大约阅读时间需要 2 分钟。

lazy solutions..... Just skip the duplicates. Then worse case of time is O(n).

 

1 class Solution { 2 public: 3     int findMin(vector
&num) { 4 int start = 0, end = num.size()-1, mid = 0; 5 if (num[start] < num[end]) return num[start]; 6 while (start < end) { 7 while (start < end && num[start] == num[start+1]) start++; 8 while (start < end && num[end] == num[end-1]) end--; 9 mid = (start + end)/2;10 if (num[mid] > num[end]) {11 start = mid + 1;12 } else {13 end = mid;14 }15 }16 return num[start];17 }18 };

 

转载于:https://www.cnblogs.com/shuashuashua/p/4349515.html

你可能感兴趣的文章
第五周学习总结
查看>>
Oracle高级查询之LAG和LEAD分析函数
查看>>
golang学习的点点滴滴:接口组合
查看>>
【挨踢人物传】frankfan:和自己赛跑的人——不要怕、不后悔!(第九期)
查看>>
anjularjs 第一天
查看>>
HSRP (不同VLAN之间的热备份路由协议)
查看>>
大数据平台一键安装OS【定制化OS镜像制作】
查看>>
git跟踪指定几个文件夹
查看>>
centos服务器到网关丢包(nf_conntrack:table full)
查看>>
Keepalive 之 高可用实现
查看>>
Ansible 之 概念和常用模块介绍
查看>>
电信2月国内市场份额52.22% 环比上月下降0.61%
查看>>
6月21日全球域名注册商(国际域名)保有量及市场份额
查看>>
批量设置0777
查看>>
centos6对xen4.2的支持
查看>>
用rsync同步公网centos yum源做本地yum源服务器
查看>>
linux sftp
查看>>
Linux的两种随机数生成器
查看>>
freeradius+mysql+pppoe认证
查看>>
与“十“俱进 阿里数据库运维10年演进之路
查看>>