Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Last active November 23, 2019 21:26
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 HauptJ/bef8402b82aa6d07a193af184c465f6e to your computer and use it in GitHub Desktop.
Save HauptJ/bef8402b82aa6d07a193af184c465f6e to your computer and use it in GitHub Desktop.
func rotate(matrix [][]int) {
reverse(matrix)
swap(matrix)
}
func reverse(matrix [][]int){
for i , j := 0, len(matrix)-1; i < j; i, j = i+1, j-1{
matrix[i], matrix[j] = matrix[j], matrix[i]
}
}
func swap(matrix [][]int){
for i := 0; i < len(matrix); i++ {
for j := i; j < len(matrix); j++ {
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment