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 ...
随机推荐
- jquery选择器玩得不6啊,只能慢慢写判断了,唉..........................
jquery选择器玩得不6啊,只能慢慢写判断了,唉..........................
- windows下Nginx与tomcat组合简单使用
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中瓦片资源越来越多,如果提高瓦片的访问效率是一个需要解决的 ...
- springMVC工程使用jreloader实现热部署
springMVC工程使用jreloader实现热部署applicationContext - ContextLoaderListener重新加载DispatcherServlet 重新加载提高开发效 ...
- windows使用技巧和工具(后面可能更新linux)
*:希望广大网友有什么建议或者好的用法工具.也能够在以下评论. 希望这是一个能够让我们更好工作起来的帖子. 工作也能舒适和开心呢. 想着好久没写过博客了吧.今天就写一篇关于windows的使用的吧.我 ...
- hive kettle 学习笔记
学习网址 http://wiki.pentaho.com/display/BAD/Transforming+Data+within+Hive
- 《HTTP权威指南》学习笔记——URL和资源
URL与资源 URL是互联网资源的标准化名称 1.浏览互联网资源 URL是浏览器寻找信息时所需的资源位置 URI是一类更通用的资源标识符,URL是它的子集. URI的两个子集:URL和URN URL提 ...
- koa-route模块
const Koa = require('koa'); const route = require('koa-route'); const app = new Koa(); const about = ...
- C语言界面显示水波纹效果
工具:VS+EasyX +素材图 EasyX首页 - EasyX Library for C++ https://www.easyx.cn/ 下载安装即可.
- Nginx 反向代理解决favicon404错误问题
# set site favicon location /favicon.ico { root html; } OR location = /favicon.ico { log_not_found o ...
- SPREAD for Windows Forms 下箭头追加行
''' <summary> ''' 下矢印の動作クラス ''' </summary> ''' <remarks></remarks> Public Cl ...