Skip to content

Instantly share code, notes, and snippets.

@vikmeup
Last active May 10, 2016 18:14
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 vikmeup/be9c0ea60c43b6959b4e9af9c48d36d9 to your computer and use it in GitHub Desktop.
Save vikmeup/be9c0ea60c43b6959b4e9af9c48d36d9 to your computer and use it in GitHub Desktop.
func flipMatrix(inout matrix: [[Int]]) {
let n = matrix.count
for i in 0..<n {
for j in i+1..<n {
let temp = matrix[i][j]
matrix[i][j] = matrix[j][i]
matrix[j][i] = temp
}
}
}
func rotate(inout matrix: [[Int]]) {
flipMatrix(&matrix)
let n = matrix.count
for i in 0..<n {
for j in 0..<n/2 {
let temp = matrix[i][j]
matrix[i][j] = matrix[i][n-j-1]
matrix[i][n-j-1] = temp
}
}
}
var matrix = [[1,2,3],[4,5,6],[7,8,9]]
rotate(&matrix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment