Simplest solution in c++ by me


#1

// Just draw 4*4 matrix
[ 1 2 3 4]
[5 6 7 8]
[9 10 11 12]
[13 14 15 16]
take pen paper and solve it manually you will understand surely.

void Solution::rotate(vector<vector<int> > &A) {
    int l=0,k=0,m=A.size()-1,n=A.size()-1;
    while(l<m && k<n)
    {
        for(int i=0;l+i<m && k+i<n;i++)
        {
            int temp = A[m][k+i];
            A[m][k+i]=A[m-i][n];
            A[m-i][n]=A[l][n-i];
            A[l][n-i]=A[l+i][k];
            A[l+i][k]=temp;
        }
        l++;
        k++;
        m--;
        n--;
    }
}