leetcode刷题系列C++-rotate image
来源:互联网 发布:知乎 张汶祥 编辑:程序博客网 时间:2024/06/06 18:21
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?
Subscribe to see which companies asked this question
class Solution {public: void rotate(vector<vector<int>>& matrix) { int length = matrix.size(); for(int i = 0; i < length; ++i) { for(int j = 0; j < length - i; ++j) { swap(matrix[i][j],matrix[length - 1 - j][length - 1 - i]); } } for(int i = 0 ; i < length / 2; ++i) { for(int j = 0; j < length ; ++j) { swap(matrix[i][j],matrix[length - 1 - i][j]); } } }};
总结:
该题主要积累的是矩阵变换的方法,此处主要是两种矩阵的变换,一个是矩阵沿着副对角线变换,另一个是矩阵沿着水平中心线变换。
还有一种方法可以先按照水平中线反转,然后按照主对角线反转。
0 0
- leetcode刷题系列C++-rotate image
- [leetcode刷题系列]Rotate Image
- [C++]LeetCode: 68 Rotate Image
- 【C++】【LeetCode】48. Rotate Image
- LeetCode c语言-Rotate Image
- [LeetCode] [C] 48. Rotate Image
- [C语言][LeetCode][48]Rotate Image
- [leetcode刷题系列]Rotate List
- leetcode 刷题之路 34 Rotate Image
- 算法系列--Rotate Image
- LeetCode算法题之Rotate Image
- LeetCode 第 48 题(Rotate Image)
- LeetCode: Rotate Image
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- [LeetCode] Rotate Image
- leetcode 67: Rotate Image
- [leetcode] Rotate Image
- Android小知识清单(二)
- html调试研究(二)-样式修改的一些规范
- VB中调用VC++开发的DLL
- Arduino: L293D for a DC motor
- 最新Eclipse SVN插件地址
- leetcode刷题系列C++-rotate image
- 原html标签分类
- Intent 传递对象
- 设计模式之——工厂模式(FactoryMethodPattern)
- html调试研究(三)-样式修改的需要了解的几个方面
- [Python学习]Python中的with语法
- java集合深度复制
- 第1章 Activity的生命周期和启动模式 1.2 Activity的启动模式
- Python split() 函数 拆分字符串 将字符串转化为列