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 ...
随机推荐
- 027-Session状态提供程序
Session分三种:1.InProc(进程内)-默认就是这种-速度快/但内存小/易丢失进程外:可以在IIS或ASPNET服务意外关闭时继续保持状态,注意此时存储到session中的对象必须支持序列化 ...
- 【转】Sqlserver将数据从一个表插入到另一个表
-- 复制表结构CREATE TABLE empty_table_name LIKE table_name; --根据table_name创建一个空表empty_table_name,empty_ta ...
- EasyUI中使用textbox赋值,setValue和setText顺序问题
注意两点: 当text和value的值不同时,一定要先赋值Value,然后赋值Text,否则text和value全部为Value的值. 如果只setValue,则使用getText和getValue得 ...
- 分布式系统Paxos算法
转载 原地址:https://www.jdon.com/artichect/paxos.html 主要加一个对应场景,如:Spring Cloud 的 Consul 集权之间的通信,其实是Raft算法 ...
- shift键有什么用?怎么用?shift键的妙用
一.当你用QQ和别人聊天时,是不是有时信息发送的特别慢呀,不要紧,只要你发信息时按shift 键信息就会很快的发送出去的! 二.当你面对一大堆窗口,却要一个一个把它们关掉时.是不是很烦啊.只要你按sh ...
- K8S学习笔记之Kubernetes数据持久化方案
在开始介绍k8s持久化存储前,我们有必要了解一下k8s的emptydir和hostpath.configmap以及secret的机制和用途. 0x00 Emptydir EmptyDir是一个空目录, ...
- [c/c++] programming之路(17)、高级指针
一.二级指针 二级指针的作用:1.函数改变外部变量指针2.外挂改变一个指针的值 #include<stdio.h> #include<stdlib.h> void main() ...
- maven开发项目中遇到的问题
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
- topcoder srm 570 div1
problem1 link 找到周期,每个周期的增量是相同的. problem2 link 对于分给某一个公司的有$c$个联通分量,其中$k$个联通分量只有1个节点,$c$个联通分量一共有$x$个节点 ...
- 北京动点飞扬软件招募【Android全职工程师】
要求: 1 至少半年2年以上android开发经验,能力第一,学历不限 2 至少5个以上正规app开发经验 3 项目周期12个月左右,要求一周内到岗 4 有意向者简历请发邮箱372900288@qq. ...