C++, Transpose (n^2) then Reverse (n^2)


#1

C++ code, Time complexity - n^2

void Solution::rotate(vector<vector > &A) {
int n = A.size();
int i = 0,z = 0,y = n;
while(i < y-1)
{
for(int j=0; j<y-1; j++)
{
swap(A[z][j],A[n-1-j][y-1]);
}
z++;
y–;
}
n = A.size();
for(int t=0,b=n-1; t<b; t++,b–)
{
for(int j=0; j<n; j++)
{
swap(A[t][j],A[b][j]);
}
}
}