给定一个 n × n 的二维矩阵表示一个图像。
将图像旋转 90 度(顺时针)。
注意:
你必须在原矩阵中旋转图像,请不要使用另一个矩阵来旋转图像。
例 1:
给出的输入矩阵 =
[
  [1,2,3],
  [4,5,6],
  [7,8,9]
],
旋转输入矩阵,使其变为 :
[
  [7,4,1],
  [8,5,2],
  [9,6,3]
]
例 2:
给出的输入矩阵 =
[
  [ 5, 1, 9,11],
  [ 2, 4, 8,10],
  [13, 3, 6, 7],
  [15,14,12,16]
],
旋转输入矩阵,使其变为 :
[
  [15,13, 2, 5],
  [14, 3, 4, 1],
  [12, 6, 8, 9],
  [16, 7,10,11]
]
详见:https://leetcode.com/problems/rotate-image/description/

Java实现:

class Solution {
public void rotate(int[][] matrix) {
int n=matrix.length;
//沿左上至右下对角线,交换对称对
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
int tmp=matrix[i][j];
matrix[i][j]=matrix[j][i];
matrix[j][i]=tmp;
}
}
//水平翻转每一行
for(int i=0;i<n;++i){
for(int j=0;j<n/2;++j){
int tmp=matrix[i][j];
matrix[i][j]=matrix[i][n-1-j];
matrix[i][n-1-j]=tmp;
}
}
}
}

参考:http://www.cnblogs.com/grandyang/p/4389572.html

https://www.cnblogs.com/lightwindy/p/8564385.html

最新文章

  1. 对session的理解
  2. python中各种结构的复杂度
  3. 【项目经验】——JSON.parse() &amp;&amp; JSON.stringify()
  4. [LeetCode][Python]14: Longest Common Prefix
  5. python web
  6. leetcode第七题--Reverse Integer
  7. JavaScript语法作业
  8. C#基础知识之属性
  9. PHP字符串函数之 sscanf echo print sprintf vsprintf printf vprintf fprintf vfprintf
  10. 一本通1530 Ant Trip
  11. windows系统中搭建Jenkins服务器
  12. laravel 数据验证
  13. Linux安装redis和部署
  14. MAC Book 共享网络连接
  15. 关于less在DW中高亮显示问题
  16. webstorm添加调试nodejs
  17. blast及其格式输出简介
  18. TCP 3-Way Handshake (SYN,SYN-ACK,ACK)
  19. 彻底禁止win10更新
  20. java.lang.IncompatibleClassChangeError:可以考虑是否是jar包冲突

热门文章

  1. 使用top命令查看系统状态
  2. 机器学习:Colorization using Optimization
  3. zabbix3.2部署
  4. 无废话WCF系列教程 -- 李林峰
  5. POJ3067(树状数组:统计数字出现个数)
  6. The Tomcat server configuration at \Servers\Tomcat v8.0 Server at localhost-config is missing. Check the server for erro
  7. Entity Framework之领域驱动设计实践
  8. sorted matrix - search &amp; find-k-th
  9. HDU 3572 Task Schedule (最大流)
  10. SetROP2