LintCode Maximum Number in Mountain
来源:互联网 发布:mhol捏脸数据 编辑:程序博客网 时间:2024/05/31 19:37
description:
Given a mountain sequence of n integers which increase firstly and then decrease, find the mountain top.
Have you met this question in a real interview? Yes
Example
Given nums = [1, 2, 4, 8, 6, 3] return 8
Given nums = [10, 9, 8, 7], return 10
使用二分法,二分法的关键点:二分出来的数据只有2个,对着两个数进行处理。
public class Solution { /** * @param nums a mountain sequence which increase firstly and then decrease * @return then mountain top */ public int mountainSequence(int[] nums) { // Write your code here if (nums == null || nums.length == 0) { return 0; } int start = 0, end = nums.length - 1; while (start + 1 < end) { int mid = start + (end - start) / 2; if (nums[mid] > nums[mid + 1]) { end = mid; } else { start = mid; } } return Math.max(nums[start], nums[end]); }}
0 0
- LintCode Maximum Number in Mountain
- Mountain Number
- lintcode:Number of Airplanes in the Sky
- [LintCode]Number of Airplanes in the Sky
- LintCode--first unique number in stream
- FZU 2019 Mountain Number
- fzu 2109 Mountain Number
- FZU - 2109 Mountain Number
- Thinking in Brokeback Mountain
- FZU2109:Mountain Number(数位DP)
- FZU2109:Mountain Number(数位DP)
- FZU2109 Mountain Number (数位DP)
- Mountain Number (数位dp)
- LintCode --number-of-airplanes-in-the-sky(数飞机)
- LintCode Number of Airplanes in the Sky(Java)
- [lintcode] - 391 Number of Airplanes in the Sky
- lintcode: Kth Smallest Number in Sorted MatrixShow result
- LintCode Kth Smallest Number in A Unsorted Array
- 日夜间模式的切换
- 基于Node.js微信授权获取用户信息
- android自定义notification UI
- MATLAB 私人使用手册之画图
- PopupWindow的创建及点击空白处弹出窗dismiss掉
- LintCode Maximum Number in Mountain
- 插件化
- 匿名对象
- 精通Apache Flink读书笔记--5
- 将字符串中的某一个关键字加粗加红
- Bugly使用
- document.body.scrollXX的用法总结
- Spring框架IOC容器
- ajax 返回JOSN 内的时间字段 jquery转换方式