顺时针打印矩阵
2016-04-05 18:55
381 查看
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; } };
相关文章推荐
- 读《构建之法》第四章有感
- 成员变量与局部变量
- opencv之Mat图像左右移
- Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水题
- jquery 1.11 attr("disabled" 无效
- String类
- 多线程使用总结
- 第五周 项目1 三角形类雏形(1)
- openwrt开发<1>内核编译
- 第6周项目2(2)画出变量占用的内存及值得变化
- 时间类(2)
- 详解 CSS 属性 - 伪类和伪元素的区别
- Intent常用flag之FLAG_ACTIVITY_CLEAR_TOP
- Spring WebSocket
- linux shell中单引号、双引号和没有引号的区别
- 部署时,出现用户代码未处理 System.Security.Cryptography.CryptographicException 错误解决方法
- 内存泄漏查找c++ new delete
- php生成mysql数据字典
- Hadoop基础教程之搭建开发环境及编写Hello World
- Hadoop-2.7.1完全分布式集群搭建完整版