LC 329 Longest Increasing Path in a Matrix(H)
Given an integer matrix, find the length of the longest increasing path.
From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).
边界判断 保证数组有行 否则返回0;
解题思路 DFS + Memorize + DP
给每个格子做 DFS 搜索
比较4个方向并且跳过超出边界或者比较小的部分
从每个格子中找出方格的最大值
Use
matrix[x][y] <= matrix[i][j]
so we don't need a visited[m][n] array。关键点是要记录下距离,以为会被重复访问到
Last updated
Was this helpful?