Very Simple solution (just do transpose and reverse each row)


#1

void Solution::rotate(vector<vector > &A) {
int r = A.size();
int c = A[0].size();

// do tranpose 
for(int i = 0; i < r; i++)
{
    for(int j = i+1; j < c; j++)
      swap(A[i][j], A[j][i]);
}
// reverse each row
for(int i = 0; i < r; i++)
{
    int j = 0, k = c-1;
    while(j < k)
    {
       swap(A[i][j], A[i][k]); 
       j++;
       k--;
    }
}

}