You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

题目大意是将矩阵做就地顺时针90度旋转。

 1 public class Solution {
 2     public void rotate(int[][] matrix) {
 3         int n = matrix.length;
 4         if(n == 0) return;
 5         for(int i = 0;i < n; i++){
 6             for(int j = 0;j < n-i; j++){//沿着副对角线旋转一次。
 7                 int tmp = matrix[i][j];
 8                 matrix[i][j] = matrix[n-j-1][n-i-1];
 9                 matrix[n-j-1][n-i-1] = tmp;
10             }
11         }
12
13         for(int i = 0;i < n/2; i++){
14             for(int j = 0;j < n; j++){//沿着中轴线,上下交换一次元素
15                 int tmp = matrix[i][j];
16                 matrix[i][j] = matrix[n-i-1][j];
17                 matrix[n-i-1][j] = tmp;
18             }
19         }
20     }
21 }

转载于:https://www.cnblogs.com/guoguolan/p/5621115.html

48. Rotate Image java solutions相关推荐

  1. 【LeetCode】48. Rotate Image (2 solutions)

    Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...

  2. 48. Rotate Image

    48. Rotate Image 题目 You are given an n x n 2D matrix representing an image.Rotate the image by 90 de ...

  3. Python JAVA Solutions for Leetcode

    Python & JAVA Solutions for Leetcode (inspired by haoel's leetcode) Remember solutions are only ...

  4. 【10】48. Rotate Image

    48. Rotate Image Total Accepted: 96625 Total Submissions: 259249 Difficulty: Medium Contributors: Ad ...

  5. LeetCode - 48. Rotate Image

    48. Rotate Image Problem's Link -------------------------------------------------------------------- ...

  6. 数据算法之二叉树平衡(BinTreeNode Rotate)的Java实现

    本文的代码来自于<数据结构与算法(JAVA语言版)>,是笔者在网上找到的资料,非正式出刊版物.笔者对代码一些比较难以理解的部分添加了注释和图解,欢迎大家来讨论. 二叉树平衡的基本思想是通过 ...

  7. leetcode 61 Rotate List ----- java

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

  8. 48. Rotate Image ~

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  9. 《每日一题》48. Rotate Image 旋转图像

    给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示例 1: 给定 m ...

最新文章

  1. python界面不同按钮实现不同功能-三、PyQt5不同方法创建菜单栏、工具栏和状态栏...
  2. Python处理PDF与CDF
  3. 打印包含在 boost::exception 中的所有数据的测试程序
  4. 微软发布新的 Azure Pipelines 功能和集成
  5. 安卓开发toolbar设置logo_Android之ToolBar的使用
  6. [TC SRM 685 div1 lev1] MultiplicationTable2
  7. 个人博客系统--项目实战
  8. .container的应用
  9. MapReduce之OutputFormat理解
  10. SQL Server - SQL Server 2016新特性之 --- Query Store
  11. 11.11 Ext JS Tooltip 出错 Uncaught TypeError: Cannot read property ‘contains‘ of null
  12. 张一鸣的心里“住着小马哥”
  13. Unity object强转int、string
  14. 仿真Windows_XP画图板的java实现
  15. Nginx 重定向 80 到443
  16. 浏览器主页被修改的解决方案
  17. vue 2.6 keep-alive 不生效问题记录点
  18. 室内定位技术现状和发展趋势
  19. 超赞!世界10个著名悖论的最终解答来了!
  20. android加载ftp图片,按键安卓版网络访问之 图片处理,FTP,HTTP 实现

热门文章

  1. 本周测试服务器角色转移系统仅开放转入,梦幻西游10月8日更新内容一览
  2. php 压缩html css,PHP实现动态压缩js与css文件的方法
  3. python的调用函数_Python函数调用
  4. Docker组队学习(一)
  5. 中文问句匹配冠军团队的NLP读书会笔记分享
  6. CNN提取文本特征,融合PMF模型实现推荐系统
  7. telnet服务器响应慢,交换机s10508 telnet登录后上反应慢
  8. html5pc转微信小程序,微信电脑版终于支持小程序 新版PC版微信实测
  9. mysql 覆盖索引 简书_mysql覆盖索引与回表
  10. eureka自我保护时间_Eureka的自我保护机制