Skip to content

Instantly share code, notes, and snippets.

@Robogeek95
Created November 18, 2020 22:16
Show Gist options
  • Save Robogeek95/d154ee7caa4f0e3765d514f48bac2ce2 to your computer and use it in GitHub Desktop.
Save Robogeek95/d154ee7caa4f0e3765d514f48bac2ce2 to your computer and use it in GitHub Desktop.
matrix-diagonal-sum
func diagonalSum(mat [][]int) int {
result := 0
for i := 0; i < len(mat); i++ {
for j := 0; j < len(mat); j++ {
if i==j || j == len(mat) -i-1 {
result+=mat[i][j]
}
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment