59. Spiral Matrix II
problem description
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
algorithm thought
和之前旋转矩阵题类似解答,可以移步到Spiral Matrix看algorithm thought
code
algorithm analysis
需要填满n*n个格子,每次填格子移动时间O(1),最后时间复杂度O(n²)
Last updated