class Solution {
public:
vector<int> spiralOrder(vector<vector<int>>& matrix) {
//剑指offer的题目
vector<int> result;
int col = matrix.size();
if (col == 0)
return result;
int row = matrix[0].size();
int up = 0;
int down = col - 1;
int left = 0;
int right = row - 1;
while (left <= right&&down >= up)
{
for (int i = left; i <= right; ++i)
result.push_back(matrix[up][i]);
if (down > up)
{
for (int i = up + 1; i <= down; ++i)
result.push_back(matrix[i][right]);
}
if (down > up)
{
for (int i = right - 1; i >= left; --i)
result.push_back(matrix[down][i]);
}
if (right > left )
{
for (int i = down - 1; i >= up + 1; --i)
result.push_back(matrix[i][left]);
}
left = left + 1;
right = right - 1;
down = down - 1;
up = up + 1;
}
return result;
}
};