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 ...
随机推荐
- 帝国cms相关调用
Loop用法:[!--temp.header--] [e:loop={6,6,0,1}] <!--标题连接/标题--> <a href="<?=$bqsr[title ...
- css中的width,height,属性与盒模型的关系
这段话很容易记住盒模型: css中盒子模型包含属性margin.border.padding.content,他们可以把它转移到我们日常生活中的盒子(箱 子)上来理解,日常生活中所见的盒子也具有这些属 ...
- CoreOS Linux available in China
CoreOS Linux 竭诚服务中国用户 今天,我们宣布一个令人振奋的消息 - CoreOS Linux 开源版本正式向中国地区提供服务!国内的用户们现在可以使用安全.自动的 CoreOS Linu ...
- Java Super 覆盖方法
子类从父类中继承方法,有时候,子类需要修改父类中定义的方法的实现,这称作方法覆盖. 比如,GeometricObject类中的toString方法返回表示集合对象的字符串,这个方法就可以被覆盖,返回表 ...
- Think Python - Chapter 15 - Classes and objects
15.1 User-defined typesWe have used many of Python’s built-in types; now we are going to define a ne ...
- R中NA和NaN的区别
NA表示的是缺失数据,missing data NaN表示无意义的数据,Not a Number, Inf-Inf Inf表示正无穷大 -Inf表示负无穷大
- C语言 负数取余的原理
负数求余数运算是一个数学问题: 任何一个整数n都可以表示成 n=k*q+r 其中0<=|r|<|q| 这里的r就是n除以q的余数,即 r==n%q 例如: -9=(-2)*4+(-1) 则 ...
- Spring事务管理 -- 挺好
Spring是SSH中的管理员,负责管理其它框架,协调各个部分的工作.今天一起学习一下Spring的事务管理.Spring的事务管理分为声明式跟编程式.声明式就是在Spring的配置文件中进行相关配置 ...
- Radiobutton编辑
package com.example.yuekao3; import java.util.ArrayList;import java.util.List; import com.baidu.farm ...
- ISBN号码
总时间限制: 1000ms 内存限制: 65536kB 描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如"x-xxx- ...