329. Longest Increasing Path in a Matrix Hard
#Array#Dynamic Programming#Depth-First Search#Breadth-First Search#Graph#Topological Sort#Memoization#Matrix
1/**
2 * [329] Longest Increasing Path in a Matrix
3 *
4 * Given an m x n integers matrix, return the length of the longest increasing path in matrix.
5 * From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/05/grid1.jpg" style="width: 242px; height: 242px;" />
9 * Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]
10 * Output: 4
11 * Explanation: The longest increasing path is [1, 2, 6, 9].
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/27/tmp-grid.jpg" style="width: 253px; height: 253px;" />
15 * Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]
16 * Output: 4
17 * Explanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
18 *
19 * Example 3:
20 *
21 * Input: matrix = [[1]]
22 * Output: 1
23 *
24 *
25 * Constraints:
26 *
27 * m == matrix.length
28 * n == matrix[i].length
29 * 1 <= m, n <= 200
30 * 0 <= matrix[i][j] <= 2^31 - 1
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/longest-increasing-path-in-a-matrix/
36// discuss: https://leetcode.com/problems/longest-increasing-path-in-a-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn longest_increasing_path(matrix: Vec<Vec<i32>>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_329() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.