题意:

  将一个n*n的矩阵顺时针旋转90度。

思路:

  都是差不多的思路,交换3次也行,反转再交换也是行的。

  1. class Solution {
  2. public:
  3. void rotate(vector<vector<int>>& matrix) {
  4. int i=, n=matrix.size();
  5. while(i*<n)
  6. {
  7. for(int j=i; j<n-i-; j++)
  8. {
  9. swap(matrix[n-j-][i],matrix[n-i-][n-j-]);
  10. swap(matrix[n-i-][n-j-],matrix[j][n-i-]);
  11. swap(matrix[j][n-i-],matrix[i][j]);
  12. }
  13. i++;
  14. }
  15. }
  16. };

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. [转]连续创建多个Oracle触发器失败,单个创建才成功的解决方法

    连续创建多个Oracle触发器失败,单个创建才成功的解决方法   1.当我连续执行创建多个触发器时,总是报编译通过,但存在警告或错误.如下:   create or replace trigger t ...

  2. linux 查看僵尸进程

    top -b -i -n 1 查看僵死进程命令 ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' 查看apache 当前进程数 ps -ef | grep ht ...

  3. Group by的使用方法

    sql中如果要分组查询,一般都会使用到group by语句,如何熟练使用group by语句呢,我分以下几点进行总结. Group by与聚合函数 Group by与Having 需要注意的地方 Gr ...

  4. 使用MediaRecorder录制视频短片

    MediaRecorder除了可用于录制音频之外,还可用于录制视频,使用MediaRecorder录制视频与录制音频的步骤基本相同.只是录制视频时不仅需要采集声音,还需要采集图像.为了让MediaRe ...

  5. 一道数学题 hduacm 5144

    题目大意:  一直初速度v和抛出速度h  求标枪抛出的最远距离: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144 显然  d=v/g*sqrt( ...

  6. uboot启动内核(3)

    nand read.jffs2 0x30007FC0 kernel; 从NAND读出内核:从哪读,从kernel分区 放到哪去   -0x30007FC0 nand read.jffs2 0x3000 ...

  7. $geoNear

    怎么使用mongoose的geoNear 2014-11-26 15:05:20|  分类: mongodb |  标签:mongoose  |举报|字号 订阅     下载LOFTER我的照片书   ...

  8. #数据结构-fib

    /////////////////////////////////////////////////////////////////////////////// // // FileName : fic ...

  9. KING小组

    KING——学习小组 小组成员及github地址&博客地址: 张静 https://github.com/loiskris/test.git  http://www.cnblogs.com/l ...

  10. 恢复drop数据

    select * from recyclebin r where r.original_name = 'MSM_EXAINVITEBIDSCHEMEHEAD' ; flashback table MS ...