leetcode 之Rotate Image(8)
这题需要搞清楚矩阵元素的位置关系,尤其是副对角线元素,沿着副对角线元素
void rotateImage(vector<vector<int>> &matrix)
{
int n = matrix.size();
//沿着副对角线翻转
for (int i = ; i < n;i++)
for (int j = ; j < n - i; j++)
{
swap(matrix[i][j], matrix[n - - j][n - - i]);
}
//沿着水平中线翻转
for (int i = ; i < n/;i++)
for (int j = ; j < n; j++)
{
swap(matrix[i][j], matrix[n - - i][j]);
}
}
leetcode 之Rotate Image(8)的更多相关文章
- [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] 61. Rotate List 旋转链表
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...
- [Leetcode][048] Rotate Image 略详细 (Java)
题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...
- 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 array ...
- 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】 Rotate List 循环链表
题目:rotate list 解法1: <span style="font-size:18px;">/**LeetCode Rotate List:Given a li ...
- [LeetCode] 189. Rotate Array 旋转数组
Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: ...
- [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
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
随机推荐
- C#基础-连接Access与SQL Server
1.连接Access数据库 string strConnection = "Provider=Microsoft.Ace.OleDb.12.0; Data Source=" + S ...
- POJ3335:Rotating Scoreboard——题解
http://poj.org/problem?id=3335 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— 看了两个小时的资料, ...
- BZOJ3994:[SDOI2015]约数个数和——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3994 https://www.luogu.org/problemnew/show/P3327#sub ...
- UVA.136 Ugly Numbers (优先队列)
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...
- [CEOI2017]Mousetrap
P4654 [CEOI2017]Mousetrap 博弈论既视感 身临其境感受耗子和管理的心理历程. 以陷阱为根考虑.就要把耗子赶到根部. 首先一定有解. 作为耗子,为了拖延时间,必然会找到一个子树往 ...
- BZOJ2791 Rendezvous
Description给定一个n个顶点的有向图,每个顶点有且仅有一条出边.对于顶点i,记它的出边为(i, a[i]).再给出q组询问,每组询问由两个顶点a.b组成,要求输出满足下面条件的x.y:1. ...
- JavaScript时间戳与其格式化
在 PHP + MySQL (日期类型为datetime) + ajax 应用中,有时候需要用 JavaScript 将时间戳类型格式化为一般的时间类型格式.下面提供一些转换的方法,比较常见的一些总结 ...
- 在Linux中新增与删除用户可以使用命令:Useradd
在Linux中新增与删除用户可以使用命令:Useradd 我们先使用man命令理解一下Useradd的用法 新增与删除用户操作需要先获取高级用户权限 输入命令:sudo -i 确定后输入高级用户密码 ...
- ContentProvider学习
1.创建类继承ContentProvider类,并实现增.删.改.查功能. public static final String AUTHORITY = "com.diysoul.lists ...
- css常见水平居中
行内元素居中 常见行内元素如文本,图片等居中时,通常是给父元素设置text-align:center 来实现.例如 HTML: <body> <div>我是文字,我要居中显示& ...