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

package leetcode_50; /***
*
* @author pengfei_zheng
* 实现二维图片顺时针旋转90度
*/
public class Solution48 {
public static void rotate(int[][] matrix) {
int len = matrix.length;
for(int i = 0; i < len; i++){
for(int j = i+1; j < len; j++){
swap(matrix,i,j,j,i);
}
}
for(int i = 0 ; i < len ; i++){
for(int j = 0 ; j < len / 2; j++){
swap(matrix,i,j,i,len-1-j);
}
}
} private static void swap(int[][] matrix, int i1,int j1, int i2,int j2) {
int temp = matrix[i1][j1];
matrix[i1][j1]=matrix[i2][j2];
matrix[i2][j2]=temp;
} public static void main(String[]args){
int [][]matrix={{1,2,3},{4,5,6},{7,8,9}};
rotate(matrix);
int len = matrix.length;
for(int i = 0 ; i < len; i++){
for(int j = 0 ; j < len; j++){
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}
LeetCode 48 Rotate Image(2D图像旋转问题)的更多相关文章
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- 每日算法37:Rotate Image (图像旋转)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image My Submissions Question (矩阵旋转)
题目大意:给一个矩阵,将其按顺时针旋转90°. 题目分析:通法是先将矩阵转置,然后再反转每一行,或者是先反转每一列,然后再将其转置.I just want to say"It's amazi ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- [leetcode 48] rotate image
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
- [leetcode]48. Rotate Image旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image (C++)
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
随机推荐
- C# 之HTTP请求get,post带重试参数
public class WebHttp { /// <summary> /// get请求带重试 /// </summary> /// <param name=&quo ...
- 删除mac系统win10启动选择项
打开终端输入:diskutil list找到EFI这个分区,挂载EFI分区diskutil mount /dev/disk0s1 回到Finder 删除除apple之外的两个文件夹就可以了(删除win ...
- Service 保活法之一
我们都知道,在Android中,Service有两种启动方式: startService 以startService()启动服务,系统将通过传入的Intent在底层搜索相关符合Intent里面信息的s ...
- Android检查设备是否可以访问互联网,判断Internet连接,测试网络请求,解析域名
安卓SDK提供了ConnectivityManager类,那么我们就可以轻松的获取设备的网络状态以及联网方式等信息. 但是要想知道安卓设备连接的网络能不能访问到Internet,就要费一番周折了. 本 ...
- 按键精灵如何调用Excel及按键精灵写入Excel数据的方法教程---入门自动操作表格
首先来建立一个新的Excel文档,在桌面上点击右键,选择[新建]-[Excel工作表],命名为[新手学员]. 现在这个新Excel文档是空白的,我们接下来会通过按键精灵的脚本来打开并写入一些数据.打开 ...
- 安卓开发笔记——关于Handler的一些总结(上)
接上篇文章<安卓开发笔记——关于AsyncTask的使用>,今天来讲下在安卓开发里"重中之重"的另一个异步操作类Handler. 今天打算先讲下关于Handler的一些 ...
- python 读取csv文件
python中有一个读写csv文件的包,直接import csv即可 新建test.csv 1.写 import csv with open("test.csv","w& ...
- 如何通过Node.js启动cesium
设置一个Web服务器通过Node.js是很容易的,只需要3个步骤: (1)从安装Node.js网站,你可以使用默认安装设置. (2)打开命令行,然后进入Cesium的根目录,通过npm install ...
- mysql中json_remove函数的使用?
需求描述: 今天看json记录,可以通过json_remove函数对一个key或多个key从个json记录中去掉. 操作过程: 1.查看一个已经存在的json表 mysql> select * ...
- js获取iframe里面的元素
直接获取不行 var win2 = document.querySelector('iframe[width = "1280" ]').contentWindow; var lo ...