[LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流
Posted Grandyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流相关的知识,希望对你有一定的参考价值。
Given an m x n
matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" touches the right and bottom edges.
Water can only flow in four directions (up, down, left, or right) from a cell to another one with height equal or lower.
Find the list of grid coordinates where water can flow to both the Pacific and Atlantic ocean.
Note:
- The order of returned grid coordinates does not matter.
- Both m and n are less than 150.
Example:
Given the following 5x5 matrix: Pacific ~ ~ ~ ~ ~ ~ 1 2 2 3 (5) * ~ 3 2 3 (4) (4) * ~ 2 4 (5) 3 1 * ~ (6) (7) 1 4 5 * ~ (5) 1 1 2 4 * * * * * * Atlantic Return: [[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]] (positions with parentheses in above matrix).
s
以上是关于[LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流的主要内容,如果未能解决你的问题,请参考以下文章
417 Pacific Atlantic Water Flow 太平洋大西洋水流
Pacific Atlantic Water Flow 解答
417. Pacific Atlantic Water Flow