原题链接在这里:https://leetcode.com/problems/path-with-maximum-minimum-value/

题目:

Given a matrix of integers A with R rows and C columns, find the maximum score of a path starting at [0,0] and ending at [R-1,C-1].

The score of a path is the minimum value in that path.  For example, the value of the path 8 →  4 →  5 →  9 is 4.

path moves some number of times from one visited cell to any neighbouring unvisited cell in one of the 4 cardinal directions (north, east, west, south).

Example 1:

Input: [[5,4,5],[1,2,6],[7,4,6]]
Output: 4
Explanation:
The path with the maximum score is highlighted in yellow.

Example 2:

Input: [[2,2,1,2,2,2],[1,2,2,2,1,2]]
Output: 2

Example 3:

Input: [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]
Output: 3

Note:

  1. 1 <= R, C <= 100
  2. 0 <= A[i][j] <= 10^9

题解:

From A[0][0], put element with index into maxHeap, sorted by element. Mark it as visited.

When polling out the currrent, check its surroundings. If not visited before, put it into maxHeap.

Until we hit the A[m-1][n-1].

Time Complexity: O(m*n*logmn). m = A.length. n = A[0].length. maxHeap add and poll takes O(logmn).

Space: O(m*n).

AC Java:

 class Solution {
int [][] dirs = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}}; public int maximumMinimumPath(int[][] A) {
int m = A.length;
int n = A[0].length; PriorityQueue<int []> maxHeap =
new PriorityQueue<int []>((a, b) -> b[2] - a[2]);
maxHeap.add(new int[]{0, 0, A[0][0]});
boolean [][] visited = new boolean[m][n];
visited[0][0] = true; int res = A[0][0];
while(!maxHeap.isEmpty()){
int [] cur = maxHeap.poll();
res = Math.min(res, cur[2]);
if(cur[0]==m-1 && cur[1]==n-1){
return res;
} for(int [] dir : dirs){
int x = cur[0] + dir[0];
int y = cur[1] + dir[1];
if(x<0 || x>=m ||y<0 || y>=n || visited[x][y]){
continue;
} visited[x][y] = true;
maxHeap.add(new int[]{x, y, A[x][y]});
}
} return res;
}
}

LeetCode 1102. Path With Maximum Minimum Value的更多相关文章

  1. 【LeetCode】1102. Path With Maximum Minimum Value 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https: ...

  2. LeetCode 1219. Path with Maximum Gold

    原题链接在这里:https://leetcode.com/problems/path-with-maximum-gold/ 题目: In a gold mine grid of size m * n, ...

  3. [LeetCode] 437. Path Sum III_ Easy tag: DFS

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  4. LeetCode(154) Find Minimum in Rotated Sorted Array II

    题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...

  5. [LeetCode] 112. Path Sum 路径和

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  6. [LeetCode] 113. Path Sum II 路径和 II

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  7. [LeetCode] 437. Path Sum III 路径和 III

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  8. [LeetCode] 666. Path Sum IV 二叉树的路径和 IV

    If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...

  9. [学习笔记] $Maximum$ $Minimum$ $identity$

    \(Maximum\) \(Minimum\) \(identity\)学习笔记 比较好玩的一个科技.具体来说就是\(max(a,b)=a+b-min(a,b)\),这个式子是比较显然的,但是这个可以 ...

随机推荐

  1. day14——装饰器

    day14 装饰器 装饰器本质就是闭包 开放封闭原则: 扩展是开放的(增加新功能),对源码是封闭的(修改已经实现的功能) 装饰器:用来装饰的工具 作用:在不改变源代码及调用方式的基础下额外增加新的功能 ...

  2. Oracle Round 函式 (四捨五入)

    Oracle Round 函式 (四捨五入)描述 : 傳回一個數值,該數值是按照指定的小數位元數進行四捨五入運算的結果.SELECT ROUND( number, [ decimal_places ] ...

  3. python自动化测试之appium环境安装

    1.安装client pip install Appium-Python-Clinet  若有两个版本的python则使用(python3 -m pip install Appium-Python-C ...

  4. Python-记事本

    1.文本颜色 格式:\[显示方式;前景色;背景色m要打印的字符串\[0m 2.format 格式 print('{}的三次方为{:*^20}'.format(a,pow(a, 3))) print(& ...

  5. ubuntu安装shadow socks-qt5

    Ubuntu16安装shadow socks-qt5 在Ubuntu下也是有GUI客户端,怎么安装请看下面: 首先,针对Ubuntu16的版本可以直接这么安装: .$ sudo add-apt-rep ...

  6. 工信部要求应用商店上新 App 检查 IPv6,这里有一份 IPv6 快速部署指南

    7 月 25 日,工业和信息化部信息通信发展司组织召开部署推进 IPv6 网络就绪专项行动电视电话会议.会议指出,加快推进 IPv6 规模部署,构建高速率.广普及.全覆盖.智能化的下一代互联网,是互联 ...

  7. GitLab+Jenkins持续集成

    一.概述 GitLab是一个代码仓库,用来管理代码.Jenkins是一个自动化服务器,可以运行各种自动化构建.测试或部署任务.所以这两者结合起来,就可以实现开发者提交代码到GitLab,Jenkins ...

  8. CentOS7配置网卡上网、安装wget、配置163yum源

    2019/09/12,CentOS 7 VMware 摘要:CentOS7安装完成(最小化安装)后,不能联网(已选择桥接网络),需要修改配置文件及配置yum源 修改配置文件 进入网卡配置目录 cd / ...

  9. 解除Ubuntu系统的root登录图形界面限制

    Ubuntu18.04.1开发团队为了Ubuntu18.04.1系统的安全,默认root不能登录图形界面,普通用户需要使用root权限时,只能通过sudo [命令] [参数] 临时使用root权限,或 ...

  10. springCloud学习4(Zuul服务路由)

    镇博图 springcloud 总集:https://www.tapme.top/blog/detail/2019-02-28-11-33 本篇中 Zuul 版本为 1.x,目前最新的是 2.x,二者 ...