---恢复内容开始---

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

Ratate the image by 90 degrees(clockwise).

Follow up:Could you do this in-place?

分析如下:

比较简单的一道题目。先沿着对角线(左下到右上)做对称变换,然后沿着竖直中心轴做对称变换。

---恢复内容结束---

class Solution {

public :

void rotate(vector <vector<int>>&matrix ){

if (matrix.empty())

return ;

int n=matrix.size();

//沿着对角线(左上到右下)做对称变换

for (int k=0;k<n;k++)

{

for (int i=0;i<k;i++)

{

int tmp=matrix[k][i];

matrix[k][i]=matrix[i][k];

matrix[i][k]=tmp;

}
}

//沿着竖直中心轴做对称变换

for (int k=0;k<n;k++){

int s=0;

int t=n-1;

while (s<t){

int tmp=matrix[k][s];

matrix[k][s]=matrix[k][s];

matrix[k][t]=tmp;

s++;

t--;

}

}

return ;

}

}

LeetCode Rotatelmage的更多相关文章

  1. 我为什么要写LeetCode的博客?

    # 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...

  2. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  3. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  6. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  7. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  8. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  9. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

随机推荐

  1. SQL 增加列、修改列、删除列

    SQL语句增加列.修改列.删除列 1.增加列: alter table tableName add columnName varchar(30) 2.1. 修改列类型: alter table tab ...

  2. 更改linux终端中用户名颜色

    用户名的设置在-下.bashrc文件中,更改PS1变量的值,如果没有就自己加一行 PS1='\[\e[32m\][\u@\h \W]#\[\e[m\] ' 32代表的是绿色前景色,\[\e[m\]是关 ...

  3. OpenStack-Neutron-VPNaaS-配置

    配置openstack版本:Juno vpnaas配置的资料很少,官网目前参考的https://wiki.openstack.org/wiki/Neutron/VPNaaS/HowToInstall比 ...

  4. nginx配置详细解析

    转自 http://blog.csdn.net/zhongguozhichuang/article/details/528168871.静态HTTP服务器 首先,Nginx是一个HTTP服务器,可以将 ...

  5. keepalived weight正负值问题(实现主服务器nginx故障后迅速切换到备服务器)

    有两台负载均衡,lb01,lb02.  lb02, priority值为100 编辑keepalived配置文件   vim /etc/keepalived/keepalived.conf ! Con ...

  6. bash vim等常用命令

    生成的txt一不小心带了./,用vim: :%s/\.\/single/single #%s/xxx/yyy/g是全文本替换,这里用\将特殊字符.和/转换成普通字符 结果还不错: ---------- ...

  7. 艾妮记账本微信小程序开发(失败版)

    这是一个寒假假期作业,要求是用web开发或者微信小程序或者手机app开发的,我本来是打算用微信小程序开发的,但由于这个后台数据库连接需要通过https认证后的浏览器再访问MySQL.所以做到后台数据库 ...

  8. JS的防抖与节流

    JS的防抖与节流在进行窗口的resize.scroll,输入框内容校验等操作时,如果事件处理函数调用的频率无限制,会加重浏览器的负担,导致用户体验非常糟糕.此时我们可以采用debounce(防抖)和t ...

  9. 了解C语言

    初学时的程序都需要打#include<stdio.h>及int main()  //int main中int 声明函数类型为整形,main为主函数:‘//’为注释的意思,后面的内容不会运行 ...

  10. 解决使用eclipse创建maven web项目时报Could not resolve archetype的问题

    前两天重装了系统,今天想写一个项目的时候出现了点问题. 在使用eclipse创建maven web项目时,点Finish后报了Could not resolve archetype的问题. Could ...