Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- https://leetcode.com/problems/rotate-image/discuss/18872/A-common-method-to-rotate-the-image
- **/
- class Solution {
- public:
- void rotate(vector<vector<int>>& matrix) {
- int n = (int)matrix.size();
- for(int i=0;i<(n)/2; i++ )
- {
- for(int j=0;j<(n+1)/2;j++ )
- {
- int pre = matrix[i][j];
- for(int k=0;k<4;k++)
- {
- int new_i = j;
- int new_j = n-1-i;
- int temp = matrix[new_i][new_j];
- matrix[new_i][new_j] = pre;
- pre = temp;
- i = new_i;
- j = new_j;
- }
- }
- }
- }
- };
Add Comment
Please, Sign In to add comment