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 ...
随机推荐
- 师兄带你轻松入门GitHub
小白:师兄,师兄,我最近总是听到Github,看起来好高大上那,可是不懂是做什么得那? 师兄:你知道微博吧,Github就是程序员的微博,你可以在这里看到全世界最优秀的程序员在做什么. 小白:师兄就是 ...
- java SE学习过程中的知识点小结(一)(很多内容过于基础,希望能帮助到学习路上的同学)————欢迎老手批评指正
①.把boolean测试放在括号内:例如while(x==4){} //当然看过很多博客,里面有工作经验的工作者说以后公司可能习惯性写(4==x) ②.所有java程序都定义在类中(也是区别于C++ ...
- Eclipse新建Java工程出现红色感叹号怎么解决?
安装了新版本的JDK之后,在Eclipse中新建Java工程出现红色感叹号怎么解决? 其实只要在Eclipse中重新设置一下JDK路径就行了 路径:右键Java工程>>Build Path ...
- Shell if条件语句
1.if条件语句:设定一个条件如果怎么,然后怎么样. (1)-gt大于.-lt小于.-ge大于等于.-le小于等于.-eq等于.-ne不等于. (2)[]内是包括变量时所使用的. (3)-f文件.-n ...
- springboot shiro和freemarker集成之权限控制完全参考手册(跳过认证,登录由三方验证,全网首发)
本文主要考虑单点登录场景,登录由其他系统负责,业务子系统只使用shiro进行菜单和功能权限校验,登录信息通过token从redis取得,这样登录验证和授权就相互解耦了. 用户.角色.权限进行集中式管理 ...
- Android组件系列----Intent详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- vue中使用cookies和crypto-js实现记住密码和加密
前端加密 使用crypto-js加解密 第一步,安装 npm install crypto-js 第二步,在你需要的vue组件内import import CryptoJS from "cr ...
- Android中intent的分类及使用
intent分为隐式和显式,显式的浅显易懂就是直呼其名,可用intent类的一个构造函数,直接传入context和想要打开的活动的名称.还可以用setcomponent方法来确定要打开的活动的名称.而 ...
- 【做题】agc006e - Rotate 3x3——分析&思维
原文链接 https://www.cnblogs.com/cly-none/p/9800105.html 题意:给出一个三行\(n\)列的矩阵.问它能否由满足\(a_{ij} = 3(j-1) + i ...
- Codeforces 788 C. The Great Mixing
题目链接:http://codeforces.com/contest/788/problem/C 一看就不能暴力$DP$,我们可以将浓度的合并操看作为在追逐一高度,每次操作前这个高度都会向上走$n$, ...