2022-03-27 18:35:17 +08:00
< p > Given a positive integer < code > n< / code > , generate an < code > n x n< / code > < code > matrix< / code > filled with elements from < code > 1< / code > to < code > n< sup > 2< / sup > < / code > in spiral order.< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< img alt = "" src = "https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg" style = "width: 242px; height: 242px;" / >
< pre >
< strong > Input:< / strong > n = 3
< strong > Output:< / strong > [[1,2,3],[8,9,4],[7,6,5]]
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > n = 1
< strong > Output:< / strong > [[1]]
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = n < = 20< / code > < / li >
< / ul >