[LeetCode] Rotate Image
来源:互联网 发布:java io开销 编辑:程序博客网 时间:2024/06/05 02:37
void rotate(vector<vector<int> > &matrix) {int n = matrix.size();for(int row = 0; row < n/2; row++){for(int col = 0; col < (n+1)/2; col++){int ele = matrix[row][col];int cnt = 0;while(cnt < 4){int newRow = col, newCol = n-row-1;int tmp = matrix[newRow][newCol];matrix[newRow][newCol] = ele;ele = tmp;row = newRow;col = newCol;cnt++;}}}}
(row, col) -> (col, n-row-1) -> (n-row-1, n-col-1) -> (n-col-1, row) -> (row, col)
如上,四个位置的像素值依次传递,这四个像素从而完成了右旋90度;
图片左上半区的像素都如此做传递,则整张图片完成右旋90度。
0 0
- LeetCode: Rotate Image
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- [LeetCode] Rotate Image
- leetcode 67: Rotate Image
- [leetcode] Rotate Image
- [Leetcode] Rotate Image
- [LeetCode]Rotate Image
- LeetCode-Rotate Image
- [leetcode] Rotate Image
- LeetCode - Rotate Image
- leetcode之Rotate Image
- LeetCode - Rotate Image
- Leetcode: Rotate Image
- LeetCode:Rotate Image
- Leetcode: Rotate Image
- Leetcode Rotate Image
- leetcode Rotate Image
- openCV中 cvSeq的用法说明【转】
- js读取json包装的map集合
- SQL递归查询(with cte as)
- mkimage.sh 分析
- LA 2512 —— Art Gallery(半平面交)
- [LeetCode] Rotate Image
- 用sql怎么表示上个月26号到本月25号这个时间段
- TRUNCATE TABLE
- i2c bus
- g++和gcc的比较
- 聚焦应用开发 2014年微信开发者大会即将召开
- 怎样在VS2010中打开VS2012的项目
- location.href提交中文参数在action中获取到为乱码
- ios网络编程(http、socket)