LeetCode Rotatelmage
---恢复内容开始---
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的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [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 ...
- 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 ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
随机推荐
- pat 1051Pop Sequence
模拟栈的过程,一开始我是用的cin来判断每行的每一个数字,然后判断回车结束.有一个点会超时,答案用数组先记录序列的方法非常好.有一个注意点就是访问s.top()的时候先要保证s.size()>0 ...
- 2014-2015 ACM-ICPC, Asia Xian Regional Contest GThe Problem to Slow Down You
http://blog.csdn.net/u013368721/article/details/42100363 回文树 建立两棵回文树,然后count处理一遍就可以了,然后顺着这两棵树的边走下去就 ...
- TLS握手、中断恢复与证书中心的原因
在双方都拿到随机数A.B.C后,将会使用这三个随机数生成一个对话密钥,然后使用该对话密钥进行对称加密通信,这种方式我们可以看到,安全性取决于随机数C的加密,前面的几个都是明文传的,这里就取决于服务器的 ...
- react脚手架搭建及配置
npm install -g create-react-app 装完之后,生成一个新的项目,可以使用下面的命令: create-react-app my-app cd my-app/yarn star ...
- shell批量修改mysql用户密码
需求 现在有这么一个需求, 需要大批量修改用户的密码, 需要注意的规则是: 必须添加的字符: *$#sjdKw% 用户名的第一位+*$#sjdKw%+用户名的最后一位,比如用户名chenglee,密码 ...
- SSM-网站后台管理系统制作(3)---Google的reCaptcha验证码
网上找了好久,也不知道怎么接入,后来看到一篇博客才搞好 reCaptcha官网:https://www.google.com/recaptcha/admin#site/344147946 参考博客:h ...
- Bootstrap3基础 table-bordered/hover 表格加外边框和鼠标悬停对应行的背景色加深
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- kindeditor4.1.11的使用方法
在引入某个外部框架/功能件的 时候, 通常是 先引入css, 后引入js. css的必要属性是rel和href, js的必要属性是charset和src. js都是用javascript的,所以 cs ...
- react开发初始配置和一些问题
1.npm run build之后,打开网页显示为空白的解决方案 初始使用的开发者应该都会使用create-react-app,初次尝试,启动没有问题,然后就测试一下build,结果发现本地文件ind ...
- 通过Python计算一个文件夹大小
在进行计算一个文件夹内容大小的时候,我们要考虑文件夹内都有什么内容,可能都是一个一个的单文件,也有可能都是子文件夹,或者二者都有,既然要计算整个文件夹的大小,我们当然要计算每一个文件的大小以及每一个子 ...