MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / min_path_sum

Method min_path_sum

64. Minimum Path Sum/src/main.rs:12–22  ·  view source on GitHub ↗
(mut grid: Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

10
11impl Solution {
12 pub fn min_path_sum(mut grid: Vec<Vec<i32>>) -> i32 {
13 let (m, n) = (grid.len(), grid[0].len());
14 for i in 1..n { grid[0][i] += grid[0][i-1]; }
15 for i in 1..m {
16 grid[i][0] += grid[i-1][0];
17 for j in 1..n {
18 grid[i][j] += std::cmp::min(grid[i-1][j], grid[i][j-1]);
19 }
20 }
21 grid[m-1][n-1]
22 }
23}
24
25#[cfg(test)]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected