Simple 3 line code in Python


#1

first interchange bottom rows with top rows till the middle row. and then take its transpose. voila.

def rotate(self, A):
    l = len(A)
    for i in range(l//2):
        A[i], A[l-i-1] = A[l-i-1], A[i]
    ans = [[A[j][i] for j in range(l)] for i in range(len(A[0]))]
    return ans