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 ...
随机推荐
- JavaScript实现字符串逆置的几种方法
1. 一般来说js实现字符串逆置输出的一般思路是: 1.将字符串转为数组,一个字符为数组的一个元素: 2.将数组倒置: 3.再将数组元素拼接为字符串. 2. 一般用到的方法有: join():该方法用 ...
- nodejs 癞子麻将
'use strict'; var _ = require('lodash'); var quick = require('quick-pomelo'); var P = quick.Promise; ...
- vim代码格式化插件clang-format
title: vim代码格式化插件clang-format date: 2017-12-12 20:28:26 tags: vim categories: 开发工具 安装vim-clang-forma ...
- excel 八位二进制转换为十六进制公式
=BIN2HEX(C16&D16&E16&F16&G16&H16&I16&J16,2)
- 21 python的魔法方法(转)
魔法方法 含义 基本的魔法方法 __new__(cls[, ...]) 1. __new__ 是在一个对象实例化的时候所调用的第一个方法2. 它的第一个参数是这个类,其他的参数是用来直接传递给 _ ...
- zw量化交易·实盘操作·系列培训班
参见: <zw量化交易·实盘操作·系列培训班> http://blog.sina.com.cn/s/blog_7100d4220102w0q5.html
- 【2017-05-18】WebForm的Repeater控件及简单控件
<%@ %> - 这里面写一些声明和引用的 <% %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <%# Eval("属性名 ...
- linux进程虚拟地址空间
转载源 在多任务操作系统中,每个进程都运行在属于自己的内存沙盘中.这个沙盘就是虚拟地址空间(Virtual Address Space),在32位模式下它是一个4GB的内存地址块.在Linux系统中, ...
- ogg12.2中的新参数 AllowOutputDir
在一个测试中,通过普通的pump进程将数据写入远端主机,启动pump进程之后进程abended.查看进程日志,提示: 2018-04-07 13:26:21 ERROR OGG-25127 R ...
- CSS 标签选择器
CSS 标签选择器 再<stype>标签内,通过指定输入标签来配置CSS样式 <html> <head> <!-- style 设置头部标签--> &l ...