Basic C++ solution using stack


#1

#include<bits/stdc++.h>
void Solution::rotate(vector<vector > &A) {
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
stack s;
for(int i=0;i<A.size();i++){
for(int j=0;j<A[i].size();j++){
s.push(A[j][i]);
}
}
for(int i=A.size()-1;i>=0;i–){
for(int j=0;j<A.size();j++){
A[i][j] = s.top();
s.pop();
}
}
}