4ms inplace transpose+reverse


  • 0
    P
    class Solution {
    public:
        void rotate(vector<vector<int>>& matrix) {
            int n = matrix.size();
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++) swap(matrix[i][j],matrix[j][i]);
            }
            for(vector<int> &vec:matrix) reverse(vec.begin(),vec.end());
        }
    };

Log in to reply
 

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