https://leetcode.com/problems/rotate-image/
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
public void Rotate(int[,] matrix)
{
int n = (int)matrix.GetLongLength(0);
int begin=0,end=n-1,num,off;
for (int layer = 0; layer < n/2; layer++)
{
for (int i = begin; i < end; i++)
{
off = i - begin;
num = matrix[begin, i];
matrix[begin, i] = matrix[end - off, begin];
matrix[end - off, begin] = matrix[end, end - off];
matrix[end, end - off] = matrix[i, end];
matrix[i, end] = num;
}
begin++;
end--;
}
}
《程序员面试金典》P114原题