A Intuitive 4ms C++ Solution


  • 1
    Y
    class Solution {
    public:
        void rotate(vector<vector<int>>& matrix) {
            int len = matrix.size(), temp;
            for(int i = 0; i < (len + 1)/2; ++i) {
                for(int j = 0; j < len/2; ++j) {
                    temp = matrix[i][j];
                    matrix[i][j] = matrix[len - j - 1][i];
                    matrix[len - j - 1][i] = matrix[len - i - 1][len - j - 1];
                    matrix[len - i - 1][len - j - 1] = matrix[j][len - i - 1];
                    matrix[j][len - i - 1] = temp;
                }
            }
        }
    };
    

Log in to reply
 

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