Pacific Atlantic Water Flow
Given anm 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:
分析
类似longest increasing path in matrix
但是这里从结果出发,从四条边开始往里走 标记可达的点用visited。
这里有2个visited 表示2个海洋,最近结果要同时满足这俩visited.
Last updated