题意:

  将一个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. poi 读取 excel (.xls) 97-2003

    1.sh.getLastRowNum() 比行数少1 private List<Map> getData(File file) throws Exception{ List<Map& ...

  2. splunk rest api search

    如下: curl -u admin:changeme -k https://localhost:8089/services/search/jobs -d search="search sou ...

  3. loadrunner 打印变量

    打印userid变量参数的信息 web_submit_form("ValidateLoginAction.do_2",  "Snapshot=t2.inf",  ...

  4. POJ 3660

    233333... Description: 就是说呢.牛是的实力室友大小之分的.然后呢.告诉你很多pair 表示任意两头牛之间的实力大小.按实力排序之后.问你一共有多少只牛的排名是确定了的. T_T ...

  5. java 面向对象编程--第十章 接口

    1.  接口可以看做是抽象类的特例.抽象类中可以定义抽象方法,也可以定义具体方法.但接口只能定义抽象方法.所有接口可以看作行为的抽象.定义接口使用关键字interface,实现接口使用关键字imple ...

  6. oracle遇到死锁杀进程

    java程序操作数据库的时候,遇到死锁:java.sql.SQLException: ORA-00060: 等待资源时检测到死锁 解决步骤: 1.找到死锁的oralce对象(表): select ob ...

  7. NSString length的坑。

    说坑,可能过头了,是我理所当然的把OC看作C了, char* cstr = "zh中文12"; NSString* s = [NSString stringWithUTF8Stri ...

  8. 最简单的PHP socket echo server。

    常有人困惑php的socket服务,现在有libevent和多线程了,但是我还是整一个select的 <?php $addr = '0.0.0.0'; $port = 1234; $socket ...

  9. 套汇问题 Floyd

    问题:套汇. 思路:Floyd 代码: #include <cstdio> #include <cstdlib> #include <ctime> #define ...

  10. [开发笔记]-多线程异步操作如何访问HttpContext?

    如何获取文件绝对路径? 在定时器回调或者Cache的移除通知中,有时确实需要访问文件,然而对于开发人员来说, 他们并不知道网站会被部署在哪个目录下,因此不可能写出绝对路径, 他们只知道相对于网站根目录 ...