Created
February 17, 2013 19:08
-
-
Save sahid/4972875 to your computer and use it in GitHub Desktop.
Rotate a Matrix N*N to 90 degrees
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
| def rotate(M): | |
| S = len(M) | |
| out = [[0] * S for x in xrange(S)] # create the output matrix | |
| for i in xrange(S): | |
| for j in xrange(S): | |
| out[i][j] = M[S-j-1][i] | |
| return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment