类似蛇形填数的板子
class Solution {
public:
vector<int> printMatrix(vector<vector<int> > matrix) {
vector<int>vt;
if(matrix.empty()||matrix[0].size()==0)return vt;
int n=matrix.size(),m=matrix[0].size();
int book[n+5][m+5];
memset(book,0,sizeof book);
int tol=1,x=0,y=0;
book[0][0]=1;
vt.push_back(matrix[0][0]);
while(tol<n*m)
{
while(y+1<m&&book[x][y+1]==0)
{
vt.push_back(matrix[x][++y]);
tol++;
book[x][y]=1;
}
while(x+1<n&&book[x+1][y]==0)
{
vt.push_back(matrix[++x][y]);
tol++;
book[x][y]=1;
}
while(y-1>=0&&book[x][y-1]==0)
{
vt.push_back(matrix[x][--y]);
tol++;
book[x][y]=1;
}
while(x-1>=0&&book[x-1][y]==0)
{
vt.push_back(matrix[--x][y]);
tol++;
book[x][y]=1;
}
}
return vt;
}
};