Rotate Image
来源:互联网 发布:江苏软件考试网 编辑:程序博客网 时间:2024/04/26 01:49
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
class Solution {public:void rotate(vector<vector<int> > &matrix) { int s = matrix.size() - 1; for (int n = s, c = 0; n > 0; n -= 2, ++c) { int tmp; for (int i = 0; i < n; ++i) { // clockwise tmp = matrix[c][i + c]; matrix[c][i + c] = matrix[s - i - c][c]; matrix[s - i - c][c] = matrix[s - c][s - i - c]; matrix[s - c][s - i - c] = matrix[i + c][s - c]; matrix[i + c][s - c] = tmp; // anticlockwise /*tmp = matrix[c][i + c]; matrix[c][i + c] = matrix[i + c][s - c]; matrix[i + c][s - c] = matrix[s - c][s - i - c]; matrix[s - c][s - i - c] = matrix[s - i - c][c]; matrix[s - i - c][c] = tmp;*/ // print here to observ how it works } } } };
0 0
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- 掉电数据块损坏引起数据库不能正常打开
- java学习笔记07-2
- Python 运算符与表达式
- JSON数据解析
- PL/SQL 异常处理
- Rotate Image
- magento 图片分离 cdn
- 常用单词缩写(不断更新)
- 周期串问题(华为入职前练习)
- Magento加速 - 神文
- Windows下使用VS2008编译OpenCV 2.1 添加Intel TBB和Python支持
- 智能电视“渐入佳境”,联想缘何摘得“智能体验冠军”?
- 微信公众平台开发(75)自定义菜单
- Hadoop源码分析之Configuration