Created
November 18, 2020 22:16
-
-
Save Robogeek95/d154ee7caa4f0e3765d514f48bac2ce2 to your computer and use it in GitHub Desktop.
matrix-diagonal-sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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