class Solution {
public:
vector<int> printMatrix(vector<vector<int> > matrix) {
int m = matrix.size(), n = matrix[0].size(), ceng = m / 2 + m % 2, N = n * m, ret = 0;
vector<int> v(N);
for(int i = 0; i < ceng; ++i){
for(int j = i; j <= n - 1 - i && ret < N; ++j)
v[ret++] = matrix[i][j];
for(int j = i + 1; j <= m - 2 - i && ret < N; ++j)
v[ret++] = matrix[j][n - 1 - i];
for(int j = n - 1 - i; j >= i && ret < N; --j)
v[ret++] = matrix[m - 1 - i][j];
for(int j = m - 2 - i; j >= i + 1 && ret < N; --j)
v[ret++] = matrix[j][i];
}
return v;
}
};