My accepted C# solution


  • 0
    T
        public void Rotate(int[,] matrix)
        {
            int n = matrix.GetLength(0);
            int a = 0;
            int b = n - 1;
    
            while (b > a) 
            {
                for (int i = a; i < b; i++) 
                {
                    int tmp = matrix[a, i];
                    matrix[a, i] = matrix[a + b - i, a];
                    matrix[a + b - i, a] = matrix[b, a + b - i];
                    matrix[b, a + b - i] = matrix[i, b];
                    matrix[i, b] = tmp;
                }
                a++;
                b--;
            }
        }

Log in to reply
 

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