Description
Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order.
Example:
1 2 3 4 5 6 7
Input: 3 Output: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]
Solution
This problem is very similar to 54. Spiral Matrix.
Just replace function append_ans
to mark_idx
:
|
|