Last active
May 10, 2016 18:14
-
-
Save vikmeup/be9c0ea60c43b6959b4e9af9c48d36d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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