class Solution:
# @param matrix, a list of lists of integers
# @return a list of lists of integers
def rotate(self, matrix):
n=len(matrix)
sub1=n//2
sub2=n//2 if n%2==0 else n//2+1
for i in range(sub1):
for j in range(sub2):
matrix[i][j], matrix[j][n-i-1], matrix[n-i-1][n-j-1], matrix[n-j-1][i] = \
matrix[n-j-1][i], matrix[i][j], matrix[j][n-i-1], matrix[n-i-1][n-j-1]
return matrix
Sunday, September 7, 2014
Leetcode: Rotate Image @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment