Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
You should return [1,2,3,6,9,8,7,4,5].
本文介绍了一种矩阵螺旋遍历算法的实现方法,通过定义边界条件并逐步移动这些边界来按螺旋顺序遍历二维矩阵中的所有元素。示例中给出了一个3x3的矩阵,并展示了如何返回按螺旋顺序排列的元素。
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
You should return [1,2,3,6,9,8,7,4,5].

被折叠的 条评论
为什么被折叠?