C++ solution for Rotate image


  • 0
    S
    class Solution {
    public:
         void rotate(vector<vector<int>>& matrix) {
            
        register int i = 0, tmp, j, la , ro ;
             const int col = matrix.size() - 1;
        for (; i <= col; ++i)
        {
        for (j = i; j <= col - i - 1; ++j)
        {
            la = col - j, ro = col - i;
            tmp = matrix[i][j];
            matrix[i][j] = matrix[la][i];
            matrix[la][i] = matrix[ro][la];
            matrix[ro][la] = matrix[j][ro];
            matrix[j][col - i] = tmp;
        }
        }
        }
    
    };
    

    My program run time is 3ms, what if we use loop unrolling to accelerate it. if you have a better solution, please to tell me, thank you.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.