C# in place solution


  • 0
    S
    public class Solution {
        public void Rotate(int[,] matrix) {
            int n = matrix.GetUpperBound(0);
            for (int i = 0; i <= n / 2 ; i++){
                for (int j = i; j < n - i; j++){
                    int temp = matrix[i, j];
                    matrix[i,j] = matrix[n - j, i];
                    matrix[n - j, i] = matrix[n - i, n - j];
                    matrix[n - i, n - j] = matrix[j, n - i];
                    matrix[j, n - i] = temp;
                }
            }
        }
    }
    

Log in to reply
 

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