leetcode 48. 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?



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


你可能感兴趣的:(LeetCode)