LeetCode(48)Rotate Image
题目
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?
分析
本地使得二维矩阵,旋转90角度。
通过实际数据分析,通过两个步骤的元素交换可实现目标:
- 按照主对角线,将对称元素交换
- 按照列,将对称列元素全部交换
即可达到,使得二维矩阵,本地旋转90个角度。
AC代码
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
if (matrix.empty())
return;
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, j = n - 1; i < j; i++, j--)
{
for (int k = 0; k < n; k++)
swap(matrix[k][i], matrix[k][j]);
}
}
};
LeetCode(48)Rotate Image的更多相关文章
- LeetCode(61) Rotate List
题目 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Giv ...
- LeetCode(189) Rotate Array
题目 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...
- LeetCode(48):旋转图像
Medium! 题目描述: 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请 系列目录 创建新表单之后,我们就可以起草申请了,申请按照严格的表单步骤和分 ...
- Thinkphp入门 四 —布局、缓存、系统变量 (48)
原文:Thinkphp入门 四 -布局.缓存.系统变量 (48) [控制器操作方法参数设置] http://网址/index.php/控制器/操作方法 [页面跳转] [变量调节器] Smarty变量调 ...
- Windows Phone开发(48):不可或缺的本地数据库
原文:Windows Phone开发(48):不可或缺的本地数据库 也许WP7的时候,是想着让云服务露两手,故似乎并不支持本地数据库,所有数据都上传上"云"数据库中.不过呢,在SD ...
- Qt 学习之路 2(48):QSortFilterProxyModel
Qt 学习之路 2(48):QSortFilterProxyModel 豆子 2013年4月11日 Qt 学习之路 2 6条评论 从本章开始,我们将逐步了解有关自定义模型的相关内容.尽管前面我们曾经介 ...
- LeetCode(275)H-Index II
题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...
- LeetCode(220) Contains Duplicate III
题目 Given an array of integers, find out whether there are two distinct indices i and j in the array ...
随机推荐
- 笔记——malloc、free、不同数据类型操作、.pyc文件、python安装第三方包、验证一个网站的所有链接有效性
C — malloc( ) and free( ) C 语言中使用malloc( )函数申请的内存空间,为什么一定要使用free释放? **malloc()函数功能:是从堆区申请一段连续的空间,函数结 ...
- win10 SQL Server 配置管理器无法启动
解决方法: 用管理员方式打开命令行 进入 “C:\Program Files (x86)\Microsoft SQL Server\140\Shared”,(有的是“C:/Program Files/ ...
- DateFormat类
package Format_daqo; import java.util.Date; import java.text.DateFormat; public class DateFormatTest ...
- Android的handler消息机制
Hnadler机制中有这么几部分构成,包括 handler.Message.Looper和MessageQueue.要想在一个线程中使用Handler的话必须要有Looper和MessageQueue ...
- AJPFX总结IO流中的缓冲思想
缓冲思想 (因为内存的运算速度要远大于硬盘的原酸速度,所以只要降低硬盘的读写次数,就可以提高效率) 1. 字节流一次读写一个数组的速度明显比一次读写一个字节的速度快很多, 2. 这是加 ...
- ASP.NET中调用事务处理的方法
/// <summary> /// 事务处理 /// </summary> /// <param name="strSql"></para ...
- XamarinAndroid 自动绑定View变量
Android 编程时我们少不了使用FindIdByView函数,在Xamarin Android开发时也需要如此.这个工作很无聊且烦人.在常规Android开发中,人们已经发明了一些方法免除这项工作 ...
- 在SQLServer 2005附加SQLServer 2008数据库异常处理
远程服务器软件系统不算新,数据库是SQL Server 2005.本地开发基本是用新的软件系统.数据库采用SQL Server 2008. 这样在用远程服务器SQL 2005选择附加SQL 2008的 ...
- select在数据库中有两种含义
select在数据库中有两种意思 (1)是赋值的意思(2)是输出,打印的意思我想你问的大概是赋值吧print和 select在数据库中都有打印输出的意思 用法是:select @aa=select* ...
- Node.js——网站访问一般流程