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

Method min_falling_path_sum

931. Maximum Frequency Stack/src/lib.rs:4–12  ·  view source on GitHub ↗
(mut matrix: Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

2
3impl 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

Calls 1

iterMethod · 0.45

Tested by

no test coverage detected