LeetCode(162) Find Peak Element
2015-08-11 09:12
357 查看
[code]class Solution { public: int findPeakElement(vector<int>& nums) { int length = nums.size(); vector<int> tmp(length + 1, 0); tmp[0] = 1; tmp[length] = -1; for(int i = 1; i < length; i++) { if(nums[i] > nums[i - 1]) tmp[i] = 1; else tmp[i] = -1; } for(int i = 0; i < length; i++) { if(tmp[i] > 0 && tmp[i + 1] < 0) return i; } } };
相关文章推荐
- 方法重构脑图
- Hashmap实现原理
- 欧几里得算法实现、正确性证明及时间复杂度分析
- Leetcode#1||Two Sum
- topic--script
- 详解php的socket通信
- 想成为嵌入式程序员应知道的 0x10 个基本问题
- win10不会玩怎么办?Windows 10 Demo网站助用户掌握新系统
- HTTP POST 网络请求
- C++ Primer 第五版: chapter 1 读书笔记
- UVA 699 The Falling Leaves (二叉树水题)
- GCD一次性代码
- Swift学习05-optional可选类型
- js判断ie浏览器
- Mac环境下svn的使用
- C#微信结合百度api获取当前用户的地理位置
- PreparedStatement(8.10)
- phpexcel下载多个sheet表单
- UIWebView获取网页的标题
- 求数列的和