Rotate Image问题及解法
来源:互联网 发布:centos快速打开终端 编辑:程序博客网 时间:2024/05/29 15:30
问题描述:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
问题分析:矩阵顺时针旋转90度可以分为两步:
1.对矩阵转置
2.对矩阵按列reverse(翻转)
过程详见代码:
class Solution {public: void rotate(vector<vector<int>>& matrix) { int n = matrix.size(); for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++) { swap(matrix[i][j],matrix[j][i]);}} for(int i = 0; i < n / 2; i++) { for(int j = 0; j < n; j++) { swap(matrix[j][i],matrix[j][n - i - 1]);}} }};
阅读全文
0 0
- Rotate Image问题及解法
- 【LeetCode】48. Rotate Image解法及注释
- Rotate Array问题及解法
- Rotate List问题及解法
- Rotate Function问题及解法
- Image Smoother问题及解法
- leetcode:Rotate Image菜鸟解法
- leetcode-48.Rotate Image 解法
- Leetcode之Rotate Image 问题
- 【LeetCode】61. Rotate List解法及分析
- Rotate String 问题使用取余解法
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- 6月英语+面试总结
- SpringMvc+MyBatis+Shiro整合,shiro的realm不能注入Bean
- javac.exe,java.exe,javaw.exe的区别
- java编程中避免空指针
- Android应用接入Bmob第三方支付
- Rotate Image问题及解法
- zynq学习笔记——HLS FAST corner导出keypoints(二)
- ubuntu 安装有道词典
- 12期 7月期刊自荐
- 北航教授多旋翼无人机教程
- VS创建和开发ocx示例
- Scala option类型和偏函数
- 1.c++中预定义宏_func_
- api-ms-win-crt-runtimel1-1-0.dll缺失