The idea is to first transpose the matrix and then flip it horizontally.

```
class Solution(object):
def rotate(self, m):
#transpose
for i in range(len(m)):
for j in range(i,len(m[0])):
if i != j:
temp = m[i][j]
m[i][j] = m[j][i]
m[j][i] = temp
#flip
for i in range(len(m)):
for j in range(len(m[0])/2):
x = len(m[0])-1 - j
temp = m[i][j]
m[i][j] = m[i][x]
m[i][x] = temp
```