Rotate Image
unknown
c_cpp
12 days ago
702 B
1
Indexable
Never
class Solution { public: void rotate(vector<vector<int>>& matrix) { int size=matrix.size(); for(int i=0;i<size;i++) { for(int y=i+1;y<size;y++) { int tmp=matrix[i][y]; matrix[i][y]=matrix[y][i]; matrix[y][i]=tmp; } } int half=size/2; for(int i=0;i<size;i++) { int endPoint=size-1; for(int y=0;y<half;y++) { int tmp=matrix[i][y]; matrix[i][y]=matrix[i][endPoint]; matrix[i][endPoint]=tmp; --endPoint; } } } };
Leave a Comment