标签:
class Solution { public: vector<int> printMatrix(vector<vector<int> > matrix) { int start=0; int heigh=matrix.size(),wide=matrix[0].size(); vector<int> res; while(heigh>start*2 && wide>start*2) { int end_wide=wide-1-start; int end_heigh=heigh-1-start; for(int i=start;i<=end_wide;i++) res.push_back(matrix[start][i]); if(start<=end_wide){ for(int i=start+1;i<=end_heigh;i++) res.push_back(matrix[i][end_wide]);} if(start<=end_wide && start<end_heigh){ for(int i=end_wide-1;i>=start;i--) res.push_back(matrix[end_heigh][i]);} if(start<end_wide&&start<end_heigh-1){ for(int i=end_heigh-1;i>start;i--) res.push_back(matrix[i][start]);} start++; } return res; } };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5356343.html