LeetCode 48. Rotate Image My Submissions Question (矩阵旋转)
题目大意:给一个矩阵,将其按顺时针旋转90°。
题目分析:通法是先将矩阵转置,然后再反转每一行,或者是先反转每一列,然后再将其转置。I just want to say"It's amazing!".(forgivig my poor English!)
代码如下(代码怎么写已经不重要了!):
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int r=matrix.size();
int c=matrix[0].size();
for(int i=0;i<r;++i){
for(int j=i+1;j<c;++j)
swap(matrix[i][j],matrix[j][i]);
for(int j=0,k=c-1;j<k;++j,--k)
swap(matrix[i][j],matrix[i][k]);
}
}
};
LeetCode 48. Rotate Image My Submissions Question (矩阵旋转)的更多相关文章
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48 Rotate Image(2D图像旋转问题)
题目链接: https://leetcode.com/problems/rotate-image/?tab=Description Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image (C++)
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- 【刷题笔记】LeetCode 48. Rotate Image
题意 原地顺时针翻转一个 n*n 的矩阵 图解 下面例子中用 5*5 矩阵做示例,如下图,我们要把该矩阵顺时针翻转90度,并且不能使用另外的矩阵空间来暂存数据,而是原地改变矩阵中数值. 我的想法是这样 ...
- [leetcode 48] rotate image
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- [leetcode]48. Rotate Image旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
随机推荐
- Web负载均衡学习笔记之四层和七层负载均衡的区别
0x00 简介 简单理解四层和七层负载均衡: ① 所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. ...
- Python入门之软件开发目录规范
本章重点: 理解在开发人标准软件时,如何布局项目目录结构,以及注意开发规范的重要性. 一.为什么要有好的目录结构 二.目录组织的方式 三.关于README的内容 四.关于requirements.tx ...
- bzoj1660 / P2866 [USACO06NOV]糟糕的一天Bad Hair Day
P2866 [USACO06NOV]糟糕的一天Bad Hair Day 奶牛题里好多单调栈..... 维护一个单调递减栈,存每只牛的高度和位置,顺便统计一下答案. #include<iostre ...
- 05: jQuery
目录: jQuery参考网站 W3school 1.1 JQuery作用 1.2 jQuery与DOM比较 与 相互转换 1.3 jQuery选择器 1.4 jQuery筛选与过滤 1.5 jQuer ...
- 20145312《网络对抗》MSF基础
20145312<网络对抗>MSF基础 实验要求 1.掌握metasploit的基本应用方式 2.掌握常用的三种攻击方式的思路 实验问答 用自己的话解释什么是exploit.payload ...
- tensorflow之神经网络实现流程总结
tensorflow之神经网络实现流程总结 1.数据预处理preprocess 2.前向传播的神经网络搭建(包括activation_function和层数) 3.指数下降的learning_rate ...
- Python3基础 os chdir 改变工作目录
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Unity3D学习笔记(二十五):文件操作
文件是什么? 存储在硬盘上的最后的节点. 文件夹是什么? 文件的上级单位称为文件夹. 文件夹的基本结构? 文件夹是层级化结构的,对于同级的文件夹不可以重名,父文件夹和子文件夹可以同名> IO:I ...
- left join联查提高执行性能
本文为博主原创,未经允许不得转载: 在项目应用中,很多功能需要多张数据库表联查,甚至跨数据库查询获取数据.sql的执行性能很能影响 服务的体验感,今天就遇到了这样问题,原来的sql是这样的: sele ...
- javascript面向对象的一些写法
因为有闭包,能返回函数,所以针对于面向对象的封装,继承,多态三个特性实现,很舒服. 代码如下: <!DOCTYPE html> <html> <head> < ...