当前位置:网站首页>LeetCode-153-寻找旋转排序数组中的最小值
LeetCode-153-寻找旋转排序数组中的最小值
2022-07-21 12:44:00 【z754916067】
题目
思路
- 之前做过一道类似的,注意一下,如果满足if(nums[start]<nums[middle] && nums[middle]<nums[end])的话,说明[start,end]是单调的,此时start位置的一定为最小值
- 如果middle等于start或者end的话,说明两者之一必有一个最小值,即可。
代码
public int findMin(int[] nums) {
if(nums.length==1) return nums[0];
//二分查找
int start=0,end=nums.length-1;
while(start<end){
int middle = start+ ((end-start)/2);
if(middle==start || middle==end) return Math.min(nums[start],nums[end]);
if(nums[start]<nums[middle] && nums[middle]<nums[end]) return nums[start];
if(nums[start]<nums[middle]) start=middle;
if(nums[middle]<nums[end]) end = middle;
}
return 0;
}
边栏推荐
- 【板栗糖GIS】arcmap——如何制作面数据的文字四至
- 从头开始学Redisson--------话题(订阅分发)
- 百度/Google等搜索引擎的信息检索搜索技巧总结
- 第十节 缓存击穿 跟着大宇学Redis--------目录帖
- [Suzhou University] information sharing of postgraduate entrance examination and re examination
- Development direction and problems of optaplanner
- Academia vs industry: can deep learning break the ceiling of video coding and decoding
- 归并排序思路及例题
- Mozilla基金会发布2022 Internet Health报告:2030年AI将为全球经济贡献15.7万亿,美去年AI投资是中国的近三倍
- 基于SqlSugar的开发框架循序渐进介绍(12)-- 拆分页面模块内容为组件,实现分而治之的处理
猜你喜欢
322. Change
ButterKnife库(一个高效的工具库,小白只记录了一个用法-不深入研究,嘻嘻)
scratch成绩查询 电子学会图形化编程scratch等级考试四级真题和答案解析2022年6月
CITIC branch Mobile has registered: it plans to raise 4billion yuan to create a listed enterprise for research and development of 5g in optical valley
专访SPORTFIVE李莹:如何用Web3的方式推动体育IP拓展“新商业版图”
Hcip notes sorting 2022/7/15
《ASP.NET Core 6框架揭秘》实例演示[04]:自定义依赖注入框架
让Matplotlib、Seaborn数据图动起来~
Number of Islands vs maximum square
Model/view architecture of QT
随机推荐
window10系统常用操作
微信小程序反编译研究
SSM框架学习
leetcode:814. 二叉树剪枝【dfs】
百度/Google等搜索引擎的信息检索搜索技巧总结
How to exit the current C application
JS array method
Yunzhou intelligent IPO was terminated: the annual revenue was 250million, the loss was 130million, and it was planned to raise 1.55 billion
【FPGA教程案例33】通信案例3——基于FPGA的BPSK调制信号产生,通过matlab测试其星座图
Sdl2 concise tutorial (I): using cmake and Conan to build sdl2 programming environment
[BSP video tutorial] BSP video tutorial No. 20: play with serial port special topics, Hal library, ll library and register implementation methods, as well as learning several key sequence diagrams in
Research on decompilation of wechat applet
中信科移动通过注册:拟募资40亿 光谷诞生研发5G的上市企业
从底层了解JVM的volatile实现,CPU Cache、缓存一致性MESI、Store BufferI、nvalidate Queue等知识
2022年最新湖北建筑安全员模拟题库及答案
Mozilla基金会发布2022 Internet Health报告:2030年AI将为全球经济贡献15.7万亿,美去年AI投资是中国的近三倍
图像文本跨模态细粒度语义对齐-置信度校正机制 AAAI2022
交互式虚拟现实技术在药物发现中的新兴潜力
OptaPlanner 发展方向与问题
云洲智能IPO被终止:年营收2.5亿亏1.3亿 曾拟募资15.5亿