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?

Solution:

     void rotate(vector<vector<int> > &matrix) {
int n = matrix.size();
for(int i = ; i < n / ; i ++) {
for(int j = i; j < n - - i; j ++){
int tmp = matrix[i][j];
matrix[i][j] = matrix[n - - j][i];
matrix[n - - j][i] = matrix[n - - i][n - - j];
matrix[n - - i][n - - j] = matrix[j][n - - i];
matrix[j][n - - i] = tmp;
}
}
}

Rotate Image [LeetCode]的更多相关文章

  1. 48. Rotate Image - LeetCode

    Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...

  2. Rotate List —— LeetCode

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  3. Rotate Array leetcode

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  4. Rotate Image leetcode java

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  5. Rotate List leetcode java

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...

  6. 189. Rotate Array - LeetCode

    Question 189. Rotate Array Solution 题目大意:数组中最后一个元素移到第一个,称动k次 思路:用笨方法,再复制一个数组 Java实现: public void rot ...

  7. 796. Rotate String - LeetCode

    Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...

  8. Rotate List || LeetCode

    /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * } ...

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. 游戏制作之路:游戏引擎选择、Mac下和Windows下UnrealEngine 4体验对比、文档及其他

    UnrealEngine 4和Unity3d的选择 订阅了UrealEngine4(UE4)开发者.我开始做网站用的是ASP.NET和C#,之后做网站虽然换用更方便的PHP(因为做的都是小网站).我想 ...

  2. 远程无法连接Mysql 的解决方案

    问题描述: 新安装了MySQL 5.6,使用root用户无法远程连接, 提示Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL ...

  3. Spring 计划

    3.0----------------------------------------------------- SCRUM 流程的步骤2: Spring 计划 1. 确保product backlo ...

  4. VMware中给Linux虚拟机添加硬盘

    给vmware的Linux虚拟机添加硬盘 1.关闭虚拟机电源,在Virtual Machine Setting对话框里点击左下角的“Add”,选择“Hard Disk”,之后选择“Create a n ...

  5. paper 110:凸优化和非凸优化

    数学中最优化问题的一般表述是求取,使,其中是n维向量,是的可行域,是上的实值函数.凸优化问题是指是闭合的凸集且是上的凸函数的最优化问题,这两个条件任一不满足则该问题即为非凸的最优化问题. 其中,是 凸 ...

  6. android-eclipse-phonegap 2..9以下(包含2.9)的项目配置

    1.搭建android.eclipse环境,下载phonegap 2.9包 2.新建android项目 3.拷贝phonegap-2.9.0\lib\android\cordova-2.9.0.jar ...

  7. PhoneGap中navigator.notification.confirm的用法详解

    navigator.notification.confirm('您确定要退出程序吗?', showConfirm, '退出程序', '确定,取消'); function showConfirm(but ...

  8. 关于linux中执行脚本或程序时指定的路径

    假设/mnt/bin 目录下存在一个名为 hello.sh 的可执行文件. 1. 若当前目录是 /mnt/bin ,可以使用 ./hello.sh 来执行这个可执行文件,但是使用 hello.sh 就 ...

  9. 【转】Repository has not been enabled to accept revision propchanges

    转载地址:http://lg-zhou.blog.163.com/blog/static/178068920111179341041/ 使用SVN提交版本信息时,注释内容写的不全.通过右键Tortoi ...

  10. Sprint第二个冲刺(第八天)

    一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图: