54. 螺旋矩阵

注意边界控制即可
class Solution
{
public:
vector spiralOrder(vector>& matrix)
{
vector res;
int left = 0;
int right = matrix[0].size() - 1;
int up = 0;
int down = matrix.size() - 1;

while (left <= right && up <= down) { for (int i = left; i <= right; ++i)//从左到右,行不变 { res.push_back(matrix[up][i]); } ++up;//下移一行 for (int i = up; i <= down; ++i)//从上到下,列不变

54. 螺旋矩阵最先出现在Python成神之路

版权声明:
作者:倾城
链接:https://www.techfm.club/p/19145.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>