You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

Do not think too much about this problem, don't be scared by the "Matrix" word. This problem can be done in an easy way.
like the picture below:
origin:rotate:

you can read as the 1st picture, and put it on a new one with a different order.

 class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
auto result = matrix;
for (int j=; j<matrix.size(); j++){
for (int i=; i<matrix.size(); i++){
result[j][matrix.size()-i-] = matrix[i][j];
}
}
matrix = result;
}
};

this is a naive one, it take extra space to rotate, there are some smarter way which can do in-place transposition. I'll check that later.

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

  10. [LeetCode] Rotate Function 旋转函数

    Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...

随机推荐

  1. JavaScript之函数

    控制语句(switch) switch(name){ case '1': age = 123; break; case '2': age = 456; break; case '3': age = 7 ...

  2. 2.6---找有环链表的开头结点(CC150)

    public ListNode detectCycle(ListNode head) { ListNode fast = head; ListNode slow = head; int flag = ...

  3. C++ 输出调试的一些技巧

    主要利用了宏和stderr... #define enable_debug #ifdef enable_debug FILL some macros/functions here #else /// ...

  4. MySQL查询交集

    MySQL表 CREATE TABLE `viewhistory` (   `viewid` int(11) NOT NULL AUTO_INCREMENT,   `uid` int(11) NOT ...

  5. Oracl各个版本的下载地址

    http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/112010-win32soft-098630-z ...

  6. Oracle: SQL组合不同字段作为一个查询条件

    前端程序传过来的值是有三个字段组合之后的结果,后端程序处理,并且将查询的数据反馈给前端. PS:不能直接使用字段RPT_NO的,因为在这条记录中RPT_NO恰好等于其他三个字段的组合值. 正确的做法是 ...

  7. 为什么学习c++?该怎么学?

    本人最近刚开始学习C++,准备记录下学习C++的历程.以下都是记录欢迎指教. 第一堂课,我们的老师告诉我们为什么学习C++,学习C++有啥用?这我也想了.但是我不了解C++,所以肯定是想不了多少的. ...

  8. swfit中的同步锁

    swfit 中 objective-c 中的@syncronized 这个东西不能用了,应该用 objc_sync_enter(self) 代码 objc_sync_exit(self) 代替!

  9. CXGrid的使用技巧

    CXGrid的使用技巧 ========================================================================== 在主从TableView中 ...

  10. Visual Studio 2013 (vs2013)中“向前定位”,“向后定位”按钮

    Visual Studio 2013 (vs2013)中默认的界面中似乎没有向前向后定位这个非常实用的功能,下面是把它们找出来的方法: 方法1:右键-->工具栏空白处-->最下面,自定义- ...