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. C++ 输出调试的一些技巧

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

  2. Linux Vsftpd 连接超时解决方法

    Linux Vsftpd 连接超时解决方法 2013-11-13 10:58:34|  分类: 默认分类|举报|字号 订阅     解决方法(http://www.lingdus.com/thread ...

  3. JavaScript——正则表达式

    1.显式创建正则表达式:var searchPattern=new RegExp(‘+s’);加号会匹配字符串中任何一个带有一个或者多个连续的s. 2.RegExp对象的方法:test和exec te ...

  4. [k]自定义上传文件按钮样式

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title> ...

  5. 【leetcode】Convert Sorted List to Binary Search Tree

    Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in as ...

  6. 自定义控件之带水印的Textbox

    代码地址: http://download.csdn.net/detail/u010312811/9553195 Windows消息处理: http://www.cnblogs.com/imstriv ...

  7. 多线程同步_Monitor

    多线程一直在学习和理解中...... Monitor类是多线程中用以实现同步的一种技术,主要是同一进程内多线程间的同步技术. Monitor类中有以下几个方法需要注意: Monitor.Enter(o ...

  8. Java对象排序

    java实现对象比较,可以实现java.lang.Comparable或java.util.Comparator接口 //Product.java import java.util.Date; //p ...

  9. GIT简单操作

    以下只是简单的bash的操作命令,个人比较喜欢用gui 打开 git bash here git clone https://github.com/自己的名字/trunk git checkout + ...

  10. Effective C++ -----条款50:了解new 和delete 的合理替换时机

    有许多理由需要写个自定的new 和delete ,包括改善效能.对heap 运用错误进行调试.收集heap 使用信息.