Question

48. Rotate Image

Solution

把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转

public void rotate(int[][] matrix) {
int n = matrix.length;
for (int i = 0; i < n / 2; i++) {
change(matrix, i);
}
} private void change(int[][] matrix, int i) {
int n = matrix.length - 1;
for (int j = i; j < n - i; j++) {
int tmp = matrix[i][j]; matrix[i][j] = matrix[n - j][i];
matrix[n - j][i] = matrix[n - i][n - j];
matrix[n - i][n - j] = matrix[j][n - i];
matrix[j][n - i] = tmp;
}
}

48. Rotate Image - LeetCode的更多相关文章

  1. [Leetcode][Python]48: Rotate Image

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 48: Rotate Imagehttps://leetcode.com/pr ...

  2. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  3. 刷题48. Rotate Image

    一.题目说明 题目是48. Rotate Image,简而言之就是矩阵顺时针旋转90度.不允许使用额外的矩阵. 经过观察(写一个矩阵,多看几遍就知道了),旋转90度后: 第1行变为len-1列(最后一 ...

  4. [LeetCode] 48. Rotate Image 旋转图像

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

  5. LeetCode 48. Rotate Image(旋转图像)

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

  6. 【一天一道LeetCode】#48. Rotate Image

    一天一道LeetCode系列 (一)题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 ...

  7. LeetCode 48 Rotate Image(2D图像旋转问题)

    题目链接: https://leetcode.com/problems/rotate-image/?tab=Description   Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...

  8. 【LeetCode】48. Rotate Image

    Difficulty:medium  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/rotate-image/ ...

  9. 【LeetCode】48. Rotate Image 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. Citus 分布式 PostgreSQL 集群 - SQL Reference(手动查询传播)

    手动查询传播 当用户发出查询时,Citus coordinator 将其划分为更小的查询片段,其中每个查询片段可以在工作分片上独立运行.这允许 Citus 将每个查询分布在集群中. 但是,将查询划分为 ...

  2. 控制算法的划分(自适应控制、预测控制、模糊控制等,PID等;蚁群算法、神经网络,还有机器学习、人工智能中的很多方法)

    一般来说,控制器的设计,分为控制框架的选取,跟参数的优化.自适应控制.预测控制.模糊控制等,跟PID一样,是控制算法(我习惯称为控制框架). 而粒子群.遗传算法(类似的还有蚁群算法.神经网络,还有机器 ...

  3. Android Studio连接SQLite数据库与SQLite Studio实时同步的实现

    最近学习用到了android开发连接数据库这一块,发现连接成功后,都要先访问安卓项目的数据库路径data/data/项目/databases,然后把对应的db文件拷出来,再在SQLite的可视化工具中 ...

  4. php弹窗后跳入另一个页面

    之前写项目时,在跳转页面前加入一个弹窗,发现弹窗没有弹出来就直接跳转了,之前使用的header跳转发现不行,换成location.href也不行,后来再location.href前加入一个parent ...

  5. 抽象方法不能为private,final或者static,为什么?

    4)抽象方法不能为private,final或者static, native, synchrozied为什么?[新手可忽略不影响继续学习]马克-to-win:抽象方法的最实质的意义在于被未来的子类覆盖 ...

  6. 自定义View的onDraw 函数不执行

    解决办法:    在自定义的View 的构造方法中添加一句话:   this.setWillNotDraw(false);解释:那么加这条语句的作用是什么?先看API:        If this ...

  7. IDEA中 mybatis-config、applicationContext.xml、log4j.properties、SpringMVC等文件没有图标标识符号,不是一个xml文件

    1. 举例说明 mybatis-config.xml文件不显示图标,识别不出该xml文件 2. 解决办法 1)先点击 File -> Settings-,然后贴入下面代码 (2) 具体操作如下图 ...

  8. kubectl creat -f 创建pod时出错

    如果创建yaml时候,sts中已经存在,但是get pod又查不到已经启动的pod可以这样 [root@k3master src]# kubectl get pod //查不到eureka NAME ...

  9. C/C++在Win32控制台播放Bad Apple

    ##前言 这里首先你需要准备一些文件,将一个Bad Apple的视频分别转换成txt和mp3格式(mp3用来作为背景音乐) 我将txt文件放到exe文件目录下的子目录files里了 转换方法可以用Ad ...

  10. 开始项目之前整理Xmind

    今天为将要做的项目整理了一份Xmind文档,每个页面,模块,功能都记了下来.带我的老师说过于详细了,但我还是新手,也不懂哪里改精简那里不该. 总结:整理Xmind文档还是很有必要的,之前这个项目我大致 ...