class Solution {
public:
vector<int> printMatrix(vector<vector<int> > matrix) {
vector<int> res;
res.clear();
int row=matrix.size();
int cloum=matrix[0].size();
int c=((row<cloum?row:cloum)-1)/2+1;
for(int i=0;i<c;i++){
for(int j=i;j<cloum-i;j++){
res.push_back(matrix[i][j]);
}
for(int k=i+1;k<row-i;k++){
res.push_back(matrix[k][cloum-i-1]);
}
for(int m=cloum-i-2;(m>=i)&&(row-i-1!=i);m--)
res.push_back(matrix[row-i-1][m]);
for(int n=row-i-2;(n>i)&&(cloum-i-1!=i);n--)
res.push_back(matrix[n][i]);
}
return res;
}
};
public:
vector<int> printMatrix(vector<vector<int> > matrix) {
vector<int> res;
res.clear();
int row=matrix.size();
int cloum=matrix[0].size();
int c=((row<cloum?row:cloum)-1)/2+1;
for(int i=0;i<c;i++){
for(int j=i;j<cloum-i;j++){
res.push_back(matrix[i][j]);
}
for(int k=i+1;k<row-i;k++){
res.push_back(matrix[k][cloum-i-1]);
}
for(int m=cloum-i-2;(m>=i)&&(row-i-1!=i);m--)
res.push_back(matrix[row-i-1][m]);
for(int n=row-i-2;(n>i)&&(cloum-i-1!=i);n--)
res.push_back(matrix[n][i]);
}
return res;
}
};