MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / diagonal_sum

Function diagonal_sum

1572-matrix-diagonal-sum.rs:33–44  ·  view source on GitHub ↗
(mat: Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

31}
32
33pub fn diagonal_sum(mat: Vec<Vec<i32>>) -> i32 {
34 let mut sum = 0;
35 let length = mat.len();
36 for (i, v) in mat.iter().enumerate() {
37 sum += v[i];
38 sum += v[length-i-1];
39 }
40 if length % 2 != 0 {
41 sum -= mat[length/2][length/2];
42 }
43 sum
44}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected