Created
July 21, 2018 03:27
-
-
Save waynejo/e08627c185dacc64c47a6426e6c19e39 to your computer and use it in GitHub Desktop.
This file contains 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 isToeplitzMatrix(matrix [][]int) bool { | |
for xBase := -len(matrix) + 1; xBase < len(matrix[0]); xBase++ { | |
yBase := -xBase | |
if yBase < 0 { | |
yBase = 0 | |
} | |
lastValue := matrix[yBase][xBase + yBase] | |
for y := yBase + 1; y < len(matrix) && xBase + y < len(matrix[0]); y++ { | |
if matrix[y][xBase + y] != lastValue { | |
return false | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment