Method
min_falling_path_sum
(mut matrix: Vec<Vec<i32>>)
Source from the content-addressed store, hash-verified
| 2 | |
| 3 | impl Solution { |
| 4 | pub fn min_falling_path_sum(mut matrix: Vec<Vec<i32>>) -> i32 { |
| 5 | let n = matrix.len(); |
| 6 | for i in 1..n { for j in 0..n { |
| 7 | if j == 0 { matrix[i][j] += matrix[i-1][j].min(matrix[i-1][j+1]) } |
| 8 | else if j == n - 1 { matrix[i][j] += matrix[i-1][j].min(matrix[i-1][j-1]) } |
| 9 | else { matrix[i][j] += matrix[i-1][j].min(matrix[i-1][j+1]).min(matrix[i-1][j-1]) } |
| 10 | }} |
| 11 | *matrix[n-1].iter().min().unwrap() |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | #[cfg(test)] |
Callers
nothing calls this directly
Tested by
no test coverage detected