Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created July 21, 2018 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynejo/e08627c185dacc64c47a6426e6c19e39 to your computer and use it in GitHub Desktop.
Save waynejo/e08627c185dacc64c47a6426e6c19e39 to your computer and use it in GitHub Desktop.
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