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

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. z-tree学习笔记

    做项目时,需要用到带复选框的tree.经比较后优选了ztree,功能强大,文档清晰. http://www.treejs.cn/v3/api.php 直接上代码吧. 1.下载ztree后.将里面需要用 ...

  2. Django框架详细介绍---视图系统

    Django视图系统 1.什么是视图 在Django中,一个视图函数/类,称为视图.实质就是一个用户自定义的简单函数,用来接收WEB请求并xing响应请求,响应的内容可以是一个HTML文件.重定向.一 ...

  3. Delphi7打开项目提示'one or more lines were too long and has been truncated'

    打开主项目文件直接显示一排'口'形状!查了下资料也问了下伙伴,这多半应该是文件损坏了,解决办法: 1. 不关D7的事,所以重装D7应该是无效的,最好看看自己是不是有备份文件,我之前有备份的所以直接覆盖 ...

  4. py-faster-rcnn代码

    1. 对proposal层NMS的解释,很清晰 注意第18~20行是拿一个数(x1)和array(x1[ [0,2,3] ])去比:

  5. ANNOTATION 注解

    注解(Annotation)很重要,未来的开发模式都是基于注解的,JPA是基于注解的,Spring2.5以上都是基于注解的,Hibernate3.x以后也是基于注解的,现在的Struts2有一部分也是 ...

  6. Missing library: xdoclet-1.2.1.jar.如何解决?

    去这里下载xdoclet-bin-1.2.1.zip http://sourceforge.net/projects/xdoclet/files/xdoclet/1.2.1/ 解压出来,比如解压到C: ...

  7. 2015全国大学生数学建模B题浅谈

    题目请自主上网获取. 分析下思路.第一问,不同时空的出租车的“供求匹配”程度. 也就是说要选取的数据要有时间和地理两个维度.实体对象是出租车.关键的问题就是地点怎么选? 选择的城市具备如下经济较发达, ...

  8. java的四大特性

    java的四大特性是:封装.继承.多态,抽象.

  9. if __name__ == "__main__":

    工欲善其事,必先利其器 # 环境:Python3.6 + win10 # 目录结构: D:\test\ # 目录 ├─ t1.py # 文件 └─ t2.py # 文件 让模块如脚本一样运行 在Pyt ...

  10. Docker 部署 elk + filebeat

    Docker 部署 elk + filebeat kibana 开源的分析与可视化平台logstash 日志收集工具 logstash-forwarder(原名lubmberjack)elastics ...