329 Longest Increasing Path in a Matrix

Longest Increasing Path in a Matrix

1
2
3
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).

对每个格子找出以此为起点用dfs找出最长的,之后,找出所有的各自的最长的。对每个格子找出最长的时候记录下来,因为格子不一定是起点,有更小的话找到该格子,直接加上就行了,不用在找一遍。