您的位置:首页 > 其它

LeetCode-48.Rotate Image

2016-05-26 16:54 260 查看
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原题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode