题目描述
Given an nxn matrix .In the given matrix, you have to find the boundary elements of the matrix.
Example 1:
Input: [[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
Output: 1 2 3 4 6 7 8 9
Example 2:
Input: [[1, 2]
[3, 4]]
Output: 1 2 3 4
Your Task:
You don't need to read or print anything. Your task is to complete the function BoundaryElements() which takes matrix as input parameter and returns a list containing the boundary elements of the matrix in the same order in which they appear in the input matrix.
Expected Time Complexity: O(n^{2})
Expected Space Complexity: O(1)
Constraints:
1 <= n <= 100
输入格式
见题面
输出格式
见题面
样例输入
[[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
样例输出
1 2 3 4 6 7 8 9