Last active
November 23, 2019 21:26
-
-
Save HauptJ/bef8402b82aa6d07a193af184c465f6e to your computer and use it in GitHub Desktop.
Rotate Matrix Clockwise: https://leetcode.com/problems/rotate-image/
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 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