Spiral Matrix II
Given a positive integer n, generate an n x n matrix filled with the integers from 1 to n^2 in spiral order.
Return the completed matrix as a 2D integer array.
Example 1
Input
n = 3Output
[[1,2,3],[8,9,4],[7,6,5]]The numbers from 1 to 9 are placed clockwise in spiral order in a 3 x 3 matrix.
Example 2
Input
n = 1Output
[[1]]A 1 x 1 matrix contains only the number 1.
Constraints
- 1 <= n <= 20