找出4个对应位置的规律即可
class Solution {
public:
void rotate(vector
<vector
<int>>& matrix
) {
int N
= matrix
.size();
for(int i
=0;i
<N
/2;i
++){
for(int j
=0;j
<N
-1-2*i
;j
++){
int* a
= &matrix
[i
][i
+j
];
int* b
= &matrix
[i
+j
][N
-1-i
];
int* c
= &matrix
[N
-1-i
][N
-1-i
-j
];
int* d
= &matrix
[N
-1-i
-j
][i
];
swap(*a
,*b
);
swap(*a
,*c
);
swap(*a
,*d
);
}
}
}
};
转载请注明原文地址:https://tech.qufami.com/read-13615.html