题意:

  将一个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 (模拟)的更多相关文章

  1. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  2. [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  ...

  3. [LeetCode] Rotate List 旋转链表

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  4. [LeetCode] Rotate Image 旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  5. LeetCode——Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

  6. [LeetCode]Rotate Image(矩阵旋转)

    48. Rotate Image     Total Accepted: 69437 Total Submissions: 198781 Difficulty: Medium You are give ...

  7. [leetcode]Rotate List @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...

  8. [leetcode]Rotate Image @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-image/ 题意: You are given an n x n 2D matrix representin ...

  9. 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 = ...

随机推荐

  1. BZOJ1218 [HNOI2003]激光炸弹

    题目后面写着DP就当它是DP吧.. 本来是扫描线+线段树的说,但是捏5000^2还是能过滴,于是暴力枚举正方形+所谓的DP就解决了. /******************************** ...

  2. pandas进行数据分析需要的一些操作

    一.查看数据 1.查看DataFrame前xx行或后xx行a=DataFrame(data);a.head(6)表示显示前6行数据,若head()中不带参数则会显示全部数据.a.tail(6)表示显示 ...

  3. Xcode连接git@osc

    Xcode 已经集成了git,建立新项目时钩选使用git,然后按照下面步骤让Xcode和git@osc 建立连接. 第一步:成生SSH密钥 打开终端命令工具,输入命令:ssh-keygen -t rs ...

  4. LA 4119 - Always an integer

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  5. 二模 (2) day2

    第一题: 题目描述: 在一个长方形框子里,最多有 N(0≤N≤6)个相异的点.在其中任何-个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界.必须等一个油滴扩展完毕才能放 ...

  6. C#同一位置切换显示两个Panel内容

    如果两个panel重合在一起,点击不同按钮切换显示不同的panel,需要xxx.BringToFront(); 1.首先让两个panel的visible都为false, 在加载页面load方法里可以让 ...

  7. bzoj 3687 bitset的运用

    题目大意: 小呆开始研究集合论了,他提出了关于一个数集四个问题:1. 子集的异或和的算术和.2. 子集的异或和的异或和.3. 子集的算术和的算术和.4. 子集的算术和的异或和.目前为止,小呆已经解决了 ...

  8. HDU 2255 二分图最佳匹配 模板题

    题目大意: 给定每一个人能支付的房子价值,每个人最多且必须拥有一套房子,问最后分配房子可得到的最大收益 抄了个别人的KM模板,就这样了... #include <cstdio> #incl ...

  9. dataTable/dataSet转换成Json格式

    using System.Text;using System.Collections.Generic; 1)dataTable转Json(表格有名称:dt.TableName) public stat ...

  10. Oracle GoldenGate 12c中的协同交付(Coordinated Delivery)

    OGG 12c中,并行交付有2种模式:集成交付.协同交付.不过集成交付只能针对目标端是oracle数据库(有版本要求)使用,而协同交付则可以在非oracle数据库上使用. 先来看2个问题, l 为什么 ...