LintCode "Find Peak Element II"
Idea is the same: climbing up the hill along one edge (Greedy)! Visualize it in your mind!
class Solution {
public:
/**
* @param A: An integer matrix
* @return: The index of the peak
*/
vector<int> findPeakII(vector<vector<int> > A)
{
int n = A.size();
int m = A[].size();
int i = , j = ;
while(i < m - && j < n - )
{
bool up = A[j - ][i] < A[j][i];
bool down = A[j + ][i] < A[j][i];
bool left = A[j][i - ] < A[j][i];
bool right= A[j][i + ] < A[j][i];
if(up && down && left && right)
{
return {j, i};
}
if(!down && j < n - )
{
j ++;
}
else if(!right && i < m - )
{
i ++;
}
}
return {-, -};
}
};
LintCode "Find Peak Element II"的更多相关文章
- [LintCode] Find Peak Element 求数组的峰值
There is an integer array which has the following features: The numbers in adjacent positions are di ...
- Lintcode: Find Peak Element
There is an integer array which has the following features: * The numbers in adjacent positions are ...
- Find Peak Element II
Description Given an integer matrix A which has the following features : The numbers in adjacent pos ...
- lintcode 75 Find Peak Element
Hi 大家,这道题是lintcode上的find peak element的题,不是leecode的那道, 这两道题是有区别的,这道题的题目中说明了:只有左右两侧的数都小于某个元素,这种才是峰值, 而 ...
- (二分查找 拓展) leetcode 162. Find Peak Element && lintcode 75. Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...
- 【Lintcode】075.Find Peak Element
题目: There is an integer array which has the following features: The numbers in adjacent positions ar ...
- LeetCode169 Majority Element, LintCode47 Majority Number II, LeetCode229 Majority Element II, LintCode48 Majority Number III
LeetCode169. Majority Element Given an array of size n, find the majority element. The majority elem ...
- [LeetCode] Find Peak Element 求数组的局部峰值
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- LeetCode 162 Find Peak Element
Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...
随机推荐
- 【ajax】FormData
- editplus 常用快捷键汇总 大小写代码折叠
文本类 新建普通文本:Ctrl+N新建浏览器窗口:Ctrl+Shift+B新建HTML页:Ctrl+Shift+N打开:Ctrl+O打开一个现有的文档文件结尾:Ctrl+End选区扩展到文档结尾处:C ...
- igv
integrative genomics viewer 下载: http://www.broadinstitute.org/igv/download 下载前要注册 导入参考基因组:http://www ...
- CI 框架隐藏index.php-ubuntu
和朋友在做一个小网站,用到了CI框架,之前测试都是在windows上,隐藏index.php也相对比较简单.但服务器是ubuntu系统,需要配置一下,根据网上看到的一些教程,结合自己电脑的特点,记录步 ...
- Spring学习笔记--spring+mybatis集成
前言: 技术的发展, 真的是日新月异. 作为javaer, 都不约而同地抛弃裸写jdbc代码, 而用各种持久化框架. 从hibernate, Spring的JDBCTemplate, 到ibatis, ...
- List,set,Map 的用法和区别
Collection├List│├LinkedList│├ArrayList│└Vector│ └Stack└SetMap├Hashtable├HashMap└WeakHashMap Collecti ...
- Codeforces Round #120 (Div. 2)
A. Vasya and the Bus 根据\(n,m\)是否为0分类讨论下. B. Surrounded 判断两圆是否有交点,否则构造的圆与两圆相切. C. STL 看代码比较清楚. void t ...
- JS中的自定义属性
<div id="div1" a="a" data-bbb="bbb">div</div> <script&g ...
- Andoid 利用ndk-stack定位崩溃代码
Android NDK自从版本R6开始, 提供了一个工具ndk-stack( 在目录{ndk_root}/中 ). 这个工具能自动分析dump下来的crash log, 将崩溃时的调用内存地址和c++ ...
- kuangbin_MST A (POJ 1251)
模板题 Kruskal直接过 调试时候居然在sort(edge + 1, edge + 1 + m)上浪费好多时间... 不过本着ACMer的心态自然要测试一下两种方法分别的速度 Kruskal : ...