-
Notifications
You must be signed in to change notification settings - Fork 0
/
25jun.txt
46 lines (42 loc) · 1.29 KB
/
25jun.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
vector<vector<int>> rotateMatrix(int k, vector<vector<int>> mat) {
// code here
int col=mat[0].size();
int row=mat.size();
int arr[row][col]={0};
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(k>col){
int newk=k%col;
int p=(col-newk)%col;
int newcol=j+p;
if(newcol>=col){
int kk=newcol%col;
arr[i][kk]=mat[i][j];
}
else{
arr[i][newcol]=mat[i][j];
}
}
else{
int p=(col-k)%col;
int newcol=j+p;
if(newcol>=col){
int kk=newcol%col;
arr[i][kk]=mat[i][j];
}
else{
arr[i][newcol]=mat[i][j];
}
}
}
}
vector<vector<int>>ans;
for(int i=0;i<row;i++){
vector<int>aa;
for(int j=0;j<col;j++){
aa.push_back(arr[i][j]);
}
ans.push_back(aa);
}
return ans;
}