Diagonal Difference

  • + 0 comments

    Rust

    fn diagonalDifference(arr: &[Vec<i32>]) -> i32 {
       let n = arr.len();
    
        let mut left2right = 0;
        let mut right2left = 0;
        for i in 0..n {
            left2right += *arr[i as usize].get(i as usize).unwrap();
            right2left += *arr[i as usize].get(n - 1 - i as usize).unwrap();
        }
    
        (left2right - right2left).abs()
    }