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

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. 蓝桥杯近三年初赛题之二(16年b组)

    1. 煤球数目 有一堆煤球,堆成三角棱锥形.具体:第一层放1个,第二层3个(排列成三角形),第三层6个(排列成三角形),第四层10个(排列成三角形),....如果一共有100层,共有多少个煤球? 请填 ...

  2. 更改linux终端中用户名颜色

    用户名的设置在-下.bashrc文件中,更改PS1变量的值,如果没有就自己加一行 PS1='\[\e[32m\][\u@\h \W]#\[\e[m\] ' 32代表的是绿色前景色,\[\e[m\]是关 ...

  3. 分治法——归并排序(mergesort)

    首先上代码. #include <iostream> using namespace std; int arr[11]; /*两个序列合并成一个序列.一共三个序列,所以用 3 根指针来处理 ...

  4. poj3133 插头dp

    #include <iostream> #include <cstdio> #include <string.h> #include <vector> ...

  5. 单源最短路——Dijkstara算法

    算法基本思想:每次找到离源点最近的一个顶点,然后以该顶点为中心进行扩展,最终得到源点到其余所有点的最短路径. 1.将所有的顶点分为两个部分:已知最短路程的顶点集合P和未知最短路径的顶点集合Q 2.设置 ...

  6. PriorityBlockingQueue 原理分析

    PriorityBlockingQueue是一个支持优先级的无界阻塞队列,直到系统资源耗尽.默认情况下元素采用自然顺序升序排列.也可以自定义类实现compareTo()方法来指定元素排序规则,或者初始 ...

  7. 《CSS世界》读书笔记(六)

    <!-- <CSS世界> 张鑫旭著 --> min-width/max-width和min-height/max-height min-width/max-width出现的场景 ...

  8. 【只要有ENA千万别用NCBI】拆分SRA文件,通过SRAtoolkits

    只要有ENA千万别用NCBI!!!! 最近开始分析网上Download的数据,一开始用人家现成的GWAS数据,后来觉得反正自己的数据到手该做的也是要做的,出来混早晚是要还的,所以就开始从头分析一些SR ...

  9. 腾讯出品的一个超棒的 Android UI 库

    腾讯出品的一个超棒的 Android UI 库 相信做 Android 久了大家都会有种体会,那就是 Android 开发相对于前端开发来说统一的 UI 开源库比较少.造成这种现象的原因一方面是大多数 ...

  10. es日常维护

    1.查看es日志curl -XGET http://10.26.41.60:9200/xdm-logs-2018.08.22?pretty=true 2.删除es日志curl -XDELETE 'ht ...