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 = ...
随机推荐
- 小记:xml画一个爱心。
aixin.xml: <!-- height:width=viewportHeight:viewportWidth --> <vector xmlns:android=" ...
- 封装自己的JS库
一.基础知识 1.点击计数 第一种: var aBtn=document.getElementsByTagName('input'); var i=0; for(i=0;i<aBtn.lengt ...
- js基础之动画(三)
一.链式运动 首先,要改进运动框架 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; ...
- 一个快速查看API的汇编和机器码的工具.发布源码
提供一个早年写的一个小工具,一直在用,赶紧很顺手,特推荐给大家. 欢迎垂询. 1,在OD正在跟踪分析某个保护壳的一段code的时候,感觉似曾相识,好像在哪里见过,好像是某个API.----这个时候你就 ...
- left join 多表关联查询
A表--left join-- B表 --on--A和B表相等的字段-- 此时AB已关联 --left join--C表--on --A(或B)与C表相等的字段 此时ABC已关联 --left j ...
- CSS盒子模型和IE浏览器
CSS盒模型图解 下面是一幅关于应用了CSS的元素是如何显示它的尺寸的图示. 在本篇文章中,所有的浏览器在计算盒模型总宽度时处理margin属性的方式都是一致的,所以我们将更多的精力放在padding ...
- Visual studio 2013的安装和单元测试
vs2013安装过程: 简单的单元测试: 1.创建新的c#类库 2.创建单元测试 3.测试结果 单元测试结束
- iOS 引导页组件 HcdGuideView
HcdGuideView HcdGuideView让你为你的app添加一个漂亮的启动页变得简单. 要求 Xcode 6 or higher iOS 7.0 or higher ARC 安装方法 手动安 ...
- IBM RSA 的语言设置
右键 IBM Rational software Architect for websphere software 快捷方式 ----> 打开文件位置 在 eclipse.ini 文件中添加参数 ...
- char 数组和 int 之间转化
上周工作结束,来到斯凯网络也将近半个月来. 没有新人的感念,最多的是将自己当作一个战士. 废话不多说,直接入正题,在没有仔细考虑问题之前我们总会 觉得:这尼玛的有毛线难度啊,不就是一个 int 转为c ...