【剑指offer】题20:顺时针打印矩阵
来源:互联网 发布:windows xp精简版 编辑:程序博客网 时间:2024/05/16 12:26
vector<int> printMatrix(vector<vector<int> > matrix){ vector<int> result; int startx(0), starty(0), endx(matrix.size()-1), endy(matrix[0].size()-1); while (startx <= endx && starty <= endy) { for (auto y = starty ; y <= endy; ++y) { result.push_back(matrix[startx][y]); //cout << matrix[x][y] << " "; } if (startx < endx) { for (auto x = startx+1; x <= endx; ++x) { result.push_back(matrix[x][endy]); //cout << matrix[x][y] << " "; } } if (starty < endy&&startx < endx) { for (auto y = endy-1; y >= starty; --y) { result.push_back(matrix[endx][y]); //cout << matrix[x][y] << " "; } } if (startx + 1 < endx &&starty < endy) { for (auto x = endx-1; x > startx; --x) { result.push_back(matrix[x][starty]); //cout << matrix[x][y] << " "; } } startx++; starty++; endx--; endy--; } return result;}
阅读全文
0 0
- 【剑指offer】题20:顺时针打印矩阵
- 剑指offer(20)顺时针打印矩阵
- 剑指offer 20 - 顺时针打印矩阵
- 剑指Offer-20-顺时针打印矩阵
- 剑指Offer 20 顺时针打印矩阵
- 剑指offer-20:顺时针打印矩阵
- 剑指offer 20 顺时针打印矩阵
- 剑指offer:第20题顺时针打印矩阵;
- 【剑指offer】顺时针打印矩阵
- 剑指offer--顺时针打印矩阵
- 剑指offer--顺时针打印矩阵
- 剑指offer 顺时针打印矩阵
- 剑指offer:顺时针打印矩阵
- 《剑指offer》顺时针打印矩阵
- 剑指offer-顺时针打印矩阵
- 剑指offer 顺时针打印矩阵
- 剑指offer:顺时针打印矩阵
- 剑指offer-顺时针打印矩阵
- 基本数据类型数据是放在栈还是常量池?
- c++ primer 读书笔记之第十章 泛型算法
- java基础之面向对象的继承
- XML总结(1)
- 剑指offer
- 【剑指offer】题20:顺时针打印矩阵
- JVM(7):JVM调优-工具篇
- linux内核启动流程
- pxe安装KS文件--实现优化IP分配
- c3p0的配置方式
- XML问题积累(1)
- Py-faster-rcnn配置模型开发环境
- python loggin模块
- pandas exercise one