a math solution(7 lines c++)


  • 0
    H

    void rotate(vector<vector<int>>& matrix) {
    int n=matrix.size()-1;
    for(int i=0;i<=n/2;i++){
    for(int j=0;j<=(n-2*i+1-2);j++){
    swap(matrix[i][i+j],matrix[i+j][n-i]);
    swap(matrix[i][i+j],matrix[n-i][n-i-j]);
    swap(matrix[i][i+j],matrix[n-i-j][i]);
    }
    }
    }


Log in to reply
 

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