54. 螺旋矩阵
注意边界控制即可
class Solution
{
public:
vector
{
vector
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成神之路。
共有 0 条评论