您的位置:首页 > 其它

leetcode 48. Rotate Image

2016-03-28 13:23 351 查看
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?

void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
int offset = 0;
while (2*(offset+1) <= matrixRowSize)
{
for (int i = offset; i < matrixRowSize - offset-1; i++)
{
int aa[4] = { matrix[offset][i], matrix[i][matrixColSize - 1 - offset],
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i], matrix[matrixRowSize - 1 - i][offset] };
matrix[offset][i] = aa[3];
matrix[i][matrixColSize - 1 - offset] = aa[0];
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i] = aa[1];
matrix[matrixRowSize - 1 - i][offset] = aa[2];
}
offset++;
}
}

accepted
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: