leetcode Spiral Matrix I
class Solution { public: vector<int> spiralOrder(vector<vector<int> > &matrix) { vector<int>v; int m=matrix.size(); if(m==0)return v; int n=matrix[0].size(); for(int i=0;2*i+1<=m&&2*i+1<=n;i++) { for(int k=i;k<n-i;k++) { v.push_back(matrix[i][k]); } for(int k=i+1;k<m-i-1;k++) { v.push_back(matrix[k][n-i-1]); } if(m-1-i>=i+1) { for(int k=n-1-i;k>=i;k--) { v.push_back(matrix[m-1-i][k]); } } if(n-1-i>=i+1) { for(int k=m-2-i;k>=i+1;k--) { v.push_back(matrix[k][i]); } } } return v; } };