summaryrefslogtreecommitdiff
path: root/matrix-diagonal-sum/src/main.rs
blob: 8ee95a0dd78490814fbadfae54b2bff078c8751a (plain)
1
2
3
4
5
6
7
8
9
10
11
fn main() {
    println!("Hello, world!");
}

struct Solution {}
impl Solution {
    pub fn diagonal_sum(mat: Vec<Vec<i32>>) -> i32 {
        mat.iter().enumerate()
            .fold(0, |acc, (i, row)| acc + row[i] + if i != row.len()-1 -i {row[row.len()-1 -i]} else {0})
    }
}