LeetCode Rotate Image (模拟)
题意:
将一个n*n的矩阵顺时针旋转90度。
思路:
都是差不多的思路,交换3次也行,反转再交换也是行的。
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int i=, n=matrix.size();
while(i*<n)
{
for(int j=i; j<n-i-; j++)
{
swap(matrix[n-j-][i],matrix[n-i-][n-j-]);
swap(matrix[n-i-][n-j-],matrix[j][n-i-]);
swap(matrix[j][n-i-],matrix[i][j]);
}
i++;
}
}
};
AC代码
LeetCode Rotate Image (模拟)的更多相关文章
- C++ STL@ list 应用 (leetcode: Rotate Array)
STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...
- [LeetCode] 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] Rotate List 旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- [LeetCode] Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode——Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- [LeetCode]Rotate Image(矩阵旋转)
48. Rotate Image Total Accepted: 69437 Total Submissions: 198781 Difficulty: Medium You are give ...
- [leetcode]Rotate List @ Python
原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...
- [leetcode]Rotate Image @ Python
原题地址:https://oj.leetcode.com/problems/rotate-image/ 题意: You are given an n x n 2D matrix representin ...
- 2016.5.16——leetcode:Rotate Array,Factorial Trailing Zeroe
Rotate Array 本题目收获: 题目: Rotate an array of n elements to the right by k steps. For example, with n = ...
随机推荐
- Tomcat编码问题
在Tomcat7中,默认URIEncoding="iso8859-1",get请求由于url会完全出现在地址栏,所以传递中文到后台会乱码,需要改成URIEncoding=" ...
- 关于call和apply的那点事儿
在JavaScript中改变闭包中的this关键字中经常用到的就是call和apply了 首先:call和apply的作用的区别是什么? 答:call和apply 的作用是相同的.都是用来改变函数th ...
- Windows内核对象
1. 内核对象 Windows中每个内核对象都只是一个内存块,它由操作系统内核分配,并只能由操作系统内核进行访问,应用程序不能在内存中定位这些数据结构并直接更改其内容.这个内存块是一个数据结构,其成员 ...
- 如果解决ubuntu tab键不能提示命令
/bin/sh is symlinked to /bin/dashTo change it, do:sudo rm /bin/shsudo ln -s /bin/bash /bin/sh 原文:htt ...
- InLineHookSSDT
//当Ring3调用OpenProcess //1从自己的模块(.exe)的导入表中取值 //2Ntdll.dll模块的导出表中执行ZwOpenProcess(取索引 进入Ring0层) //3进入R ...
- 小记:获取系统时间的long值,格式化成可读时间。
/** * 返回的字符串形式是形如:2013年10月20日 20:58 * */ public static String formatTimeInMillis(long timeInMillis) ...
- WEBService动态调用代码
BasicHttpBinding bind = new BasicHttpBinding(); bind.MaxReceivedMessageSize = int.MaxValue; Endpoint ...
- 一模 (6) day1
第一题: 题目大意: 一个n的全排列A[i]是单峰的,当且仅当存在某个x使得A[1]<A[2]<...<A[x]>A[x+1]>...>A[n]. 试求 n 的单峰 ...
- GITHUB的初次使用
对于一个从未用过 接触过github的人来说,达到一个最终的成功真可谓是历经千辛万苦.在这里真的感谢我们的小组组长,我遇到的问题除了自己的查到的,剩 下的基本上都是组长帮我解决的.当所有 ...
- Redhat6.x下如何进行远程安装虚拟机
远程主机IP:192.168.122.1 远程主机名:server1.example.com 本地主机IP:192.168.122.2 本地主机名:server2.example.com 1.登录到远 ...