P19955 [GeeksforGeeks] C matrix rotation by 180 degree0745
普及-
题目描述

Given a square matrix of size N X N, turn it by 180 degrees in anticlockwise direction without using extra memory.

Example 1:
Input: N = 4,
matrix = {{1, 2, 3, 4},
{5, 6, 7 ,8},
{9, 10, 11, 12},
{13, 14, 15, 16}}
Output: {{16, 15, 14, 13},
{12, 11, 10, 9},
{8, 7, 6, 5},
{4, 3, 2, 1}}
Example 2:
Input: N = 2,
matrix = {{1, 2},
{3, 4}}
Output: {{4, 3},
{2, 1}}

Your Task:
You don't need to read or print anything. Your task is to complete the function rotate() which takes matrix as input parameter and rotate the matrix by 180 degree wihtout using extraa memory. You have to rotate the matrix in-place which means you have to modify the input matrix directly.

Expected Time Complexity: O(N^{2})
Expected Space Complexity: O(1)

Constraints:
1 ≤ N ≤ 500

输入格式

见题面

输出格式

见题面

样例输入
N = 4, matrix = {{1, 2, 3, 4}, {5, 6, 7 ,8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
样例输出
{{16, 15, 14, 13}, {12, 11, 10, 9}, {8, 7, 6, 5}, {4, 3, 2, 1}}