leetcode 162 —— Find Peak Element
来源:互联网 发布:彩票k线图软件 编辑:程序博客网 时间:2024/05/17 07:35
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) {stack<int> stk;stk.push(0);int i = 1;for (i; i < nums.size(); i++) {if (nums[i] >= nums[i - 1])stk.push(i);elsereturn stk.top();}return stk.top();}};
0 0
- leetcode 162 —— Find Peak Element
- Find Peak Element—LeetCode
- leetcode——Find Peak Element
- Find Peak Element —— Leetcode
- leetcode——Find Peak Element
- 【leetcode】Array——Find Peak Element(162)
- LeetCode(162) Find Peak Element
- [leetcode 162] Find Peak Element
- leetcode-162 Find Peak Element
- [LeetCode 162]Find Peak Element
- LeetCode 162 Find Peak Element
- [leetcode] #162 Find Peak Element
- Find Peak Element - LeetCode 162
- Leetcode[162]-Find Peak Element
- leetcode-162-Find Peak Element
- !leetcode[162]:Find Peak Element
- LeetCode(162) Find Peak Element
- [Leetcode 162] Find Peak Element
- 控件的一些基本操作,设置颜色,自动连接,插入图片,padding,ellipsize。
- Android应用程序组件(四)
- HDU 5200 Trees(线段树 离线应用)经典
- 并发编程网
- Pascal数组递推
- leetcode 162 —— Find Peak Element
- BFS解迷宫问题
- 一、数据结构 读书笔记(一)基本概念与算法
- WebView 用法
- 杭电ACM1372——Knight Moves~~BFS
- poj1995 Raising Modulo Numbers【快速幂】
- Activity中几个主要函数详解
- 调用按钮内部imageView的尺寸
- android去掉activity默认的title bar