59. Spiral Matrix II

Medium

5.7K

234

Given a positive integer `n`

, generate an `n x n`

`matrix`

filled with elements from `1`

to `n`

in spiral order.^{2}

**Example 1:**

Input:n = 3Output:[[1,2,3],[8,9,4],[7,6,5]]

**Example 2:**

Input:n = 1Output:[[1]]

**Constraints:**

`1 <= n <= 20`

Accepted

497.5K

Submissions

713.9K

Acceptance Rate

69.7%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved