54. Spiral Matrix
Description
Difficulty: Medium
Related Topics: Array, Matrix, Simulation
Given an m x n
matrix
, return all elements of the matrix
in spiral order.
Example 1:
1 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] |
Example 2:
1 | Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] |
Constraints:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 10
-100 <= matrix[i][j] <= 100
Hints/Notes
- 2023/08/09
- Traverse all four sides in one iteration
- 0x3F’s solution(checked)
Solution
cleaner solution
1 | class Solution { |
Language: C++
1 | class Solution { |