Skip to content

Instantly share code, notes, and snippets.

@mumunuu
Last active January 20, 2021 07:27
Show Gist options
  • Save mumunuu/fa5f36d55649f129ddf38d734f06735a to your computer and use it in GitHub Desktop.
Save mumunuu/fa5f36d55649f129ddf38d734f06735a to your computer and use it in GitHub Desktop.
algorithm(leetcode) Rotate Image
func rotate(matrix [][]int) {
matrixLength := len(matrix)
for i := 0; i < matrixLength; i++ {
for j := i; j < matrixLength; j++ {
tmp := matrix[j][i]
matrix[j][i] = matrix[i][j]
matrix[i][j] = tmp
}
}
for i := 0; i < matrixLength; i++ {
for j := 0; j < matrixLength/2; j++ {
tmp := matrix[i][j]
matrix[i][j] = matrix[i][matrixLength-j-1]
matrix[i][matrixLength-j-1] = tmp
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment