局部极大值
来源:互联网 发布:日本人对二战 知乎 编辑:程序博客网 时间:2024/06/05 00:24
leetcode练习地址
A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1]
, find a peak element and return its index.
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
You may imagine that num[-1] = num[n] = -∞
.
For example, in array [1, 2, 3, 1]
, 3 is a peak element and your function should return the index number 2.
class Solution {public: int findPeakElement(vector<int>& nums) { int iLeft = 0; int iRight = nums.size()-1; int iMid = (iLeft + iRight) / 2; while(iLeft != iRight){ if(nums[iMid] > nums[iMid+1]) iRight = iMid; else iLeft = iMid+1; iMid = (iLeft + iRight) / 2; } return iMid; }};
局部极大值在[i,n]
阅读全文
0 0
- 局部极大值
- 局部极大值
- 1331: 局部极大值
- 求矩阵的局部极大值
- 求矩阵的局部极大值
- 求矩阵的局部极大值(15)
- 求矩阵的局部极大值(15)
- opencv实现简单的局部极大值求解
- 数组-09. 求矩阵的局部极大值(15)
- 8-2. 求矩阵的局部极大值(15)
- c语言练习 8-2. 求矩阵的局部极大值
- PAT:8-2. 求矩阵的局部极大值(15)
- 8-2. 求矩阵的局部极大值(15)
- 08-2. 求矩阵的局部极大值(15)
- 08-2. 求矩阵的局部极大值(15)
- 08-2. 求矩阵的局部极大值(15)
- 08-2. 求矩阵的局部极大值(15)
- 08-2. 求矩阵的局部极大值(15)
- Linux-NFS——配置过程
- 《剑指offer》连续子数组的最大和
- flex 基础
- cscope使用简介
- Ubuntu下Android Studio的设备连接后设备名后为[null]的解决方法
- 局部极大值
- 双日历插件My97DatePicker
- Git学习笔记
- 解决Android设置Style中Activity的退出动画无效问题
- js 和 oc 调用
- java文本之撤销与恢复
- 【二叉树】二分查找树,中序遍历,统计出现次数最多的节点【Add to List 501. Find Mode in Binary Search Tree】
- git clone 简介
- 类和对象