[LeetCode] Rotate Image
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的更多相关文章
- C++ STL@ list 应用 (leetcode: Rotate Array)
STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...
- [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 ...
- [LeetCode] Rotate List 旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- [LeetCode] Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode——Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- [LeetCode]Rotate Image(矩阵旋转)
48. Rotate Image Total Accepted: 69437 Total Submissions: 198781 Difficulty: Medium You are give ...
- [leetcode]Rotate List @ Python
原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...
- [leetcode]Rotate Image @ Python
原题地址:https://oj.leetcode.com/problems/rotate-image/ 题意: You are given an n x n 2D matrix representin ...
- 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 = ...
- [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 ...
随机推荐
- PyCharm 5 破解注册方法
方法: 调整时间到2038年. 申请30天试用 退出pycharm 时间调整回来即可. 或者: 注册时选择 License server ,填 http://idea.lanyus.com ,然后点击 ...
- BZOJ 4455: [Zjoi2016]小星星
Sol 容斥原理+树形DP. 这道题用的容斥思想非常妙啊!主要的思路就是让所有点与S集合中的点对应,可以重复对应,并且可以不用对应完全(意思是是S的子集也可以).这样他有未对应完全的,那就减去,从全都 ...
- faac编码aac
// faacode.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <faac.h> #include &l ...
- phpcms不显示验证码
只需修改./caches/configs/system.php即可 1.本地域名如果是 http://localhost 如果所有的文件都在根目录下(例如apache下的htdocs或www),此时, ...
- Appium+Robotframework实现Android应用的自动化测试-7:模拟器频繁挂掉的解决方案
如果测试用例比较多,则当持续运行多个测试用例后,经常会出现模拟器崩溃或者Appium无法连接到该模拟器的情况出现. 经过分析,本人认为这应该是模拟器或者Appium的缺陷造成的,目前并没有直接的解决方 ...
- 【转载】通过JDBC对MySQL数据库的增删改查
通过JDBC进行简单的增删改查(以MySQL为例) 目录 前言:什么是JDBC 一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JDBC基本操 ...
- ABAP ALV单个单元格状态编辑-简单版本
*&---------------------------------------------------------------------* *& Report ZPPR0024 ...
- IP子网划分
CIDR值: 1.掩码255.0.0.0:/8(A类地址默认掩码) 2.掩码255.128.0.0:/9 3.掩码255.192.0.0:/10 4.掩码255.224.0.0:/11 5.掩码255 ...
- 【leetcode】Spiral Matrix(middle)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- .Net SqlDbHelper
using System.Configuration; using System.Data.SqlClient; using System.Data; namespace ExamDAL { clas ...