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"的更多相关文章

  1. [LintCode] Find Peak Element 求数组的峰值

    There is an integer array which has the following features: The numbers in adjacent positions are di ...

  2. Lintcode: Find Peak Element

    There is an integer array which has the following features: * The numbers in adjacent positions are ...

  3. Find Peak Element II

    Description Given an integer matrix A which has the following features : The numbers in adjacent pos ...

  4. lintcode 75 Find Peak Element

    Hi 大家,这道题是lintcode上的find peak element的题,不是leecode的那道, 这两道题是有区别的,这道题的题目中说明了:只有左右两侧的数都小于某个元素,这种才是峰值, 而 ...

  5. (二分查找 拓展) 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 ...

  6. 【Lintcode】075.Find Peak Element

    题目: There is an integer array which has the following features: The numbers in adjacent positions ar ...

  7. 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 ...

  8. [LeetCode] Find Peak Element 求数组的局部峰值

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  9. LeetCode 162 Find Peak Element

    Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...

随机推荐

  1. PAT (Basic Level) Practise:1033. 旧键盘打字

    [题目链接] 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2行中分别给出坏掉的那些键.以 ...

  2. 11. Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  3. JS的跨域问题

    1.什么是跨域? 跨域问题是由于javascript语言安全限制中的同源策略造成的. 2.什么是同源策略: 同源策略是指一段脚本只能读取来自同一来源的窗口和文档的属性,这里的同一来源指的是主机名.协议 ...

  4. 转:linux 修改sftp服务默认提供者sshd的session timeout

    ssh连接超时问题解决方案: 1.修改server端的etc/ssh/sshd_config ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后cl ...

  5. NOI 银河英雄传说

    并查集水题,记录祖先,大小和深度即可,每次用祖先的大小和深度更新后代的深度. #include <cstdio> #include <iostream> #include &l ...

  6. Python学习(2)——编码

    今天写了个程序但是在DOS窗口和IDEL窗口调试的结果不一样,有些郁闷~ #!/usr/bin/env python #coding=utf-8 #python version:2.7.3 #syst ...

  7. VC线程中操作控件,引起程序卡死的问题。

    [问题还原] 线程中操作控件,具体为控制一个按键的使能,使能后结束线程. 主程序中有一个死循环,等待线程结束. 然后,就没有然后了-- [解决方案] 在主程序死循环中,如果检测到界面消息,优先处理掉.

  8. Oracle升级前备份和失败回退

    一.升级前备份 1.软件备份[root@localhost backup]# su - oracle [oracle@localhost ~]$ cd $ORACLE_HOME[oracle@loca ...

  9. Hadoop 安装记录

    第一步:打开/etc 下面的 profile文件,在其中加入环境变量设置的代码 done JAVA_HOME=/home/hadoop/installer/jdk7u65 PATH=$JAVA_HOM ...

  10. 不要告诉我你懂margin

    分类: Html/CSS | 转载请注明: 出自 海玉的博客 本文地址: http://www.hicss.net/do-not-tell-me-you-understand-margin/ 你真的了 ...