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].
思路:打印如螺旋桨,每个矩形框的起始点为(x,x),如果row>2*x||col>2*x则在这个矩形框打印结束。每个矩形框的打印路径为(x,x)---->(col-x-1,x)--->(col-x-1,row-x-1)---->(x,row-x-1)----->(x,x)
class Solution {
public:
void spiralOrderHelper(vec......
阅读全文