LeetCode 48. Rotate Image(旋转)
2016-05-21 05:34
477 查看
原题网址:https://leetcode.com/problems/rotate-image/
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?
方法:直接旋转。
![](http://img.blog.csdn.net/20160521053412082?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
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?
方法:直接旋转。
public class Solution { public void rotate(int[][] matrix) { for(int i=0; i<matrix.length/2; i++) { for(int j=0; j<(matrix.length+1)/2; j++) { int t = matrix[i][j]; matrix[i][j] = matrix[matrix.length-1-j][i]; matrix[matrix.length-1-j][i] = matrix[matrix.length-1-i][matrix.length-1-j]; matrix[matrix.length-1-i][matrix.length-1-j] = matrix[j][matrix.length-1-i]; matrix[j][matrix.length-1-i] = t; } } } }
相关文章推荐
- LeetCode 47. Permutations II(排列)
- LeetCode 46. Permutations(排列)
- python基础
- python基础
- LeetCode 45. Jump Game II(跳格子)
- 山寨Besiege(四)操控轴
- BigBlueButton简介
- Moodle简介
- Bigbluebutton服务执行过程及相关配置文件
- LeetCode 44. Wildcard Matching(模糊匹配)
- 大数据和Android
- Mvp架构的使用
- 【三分法/数学公式】B君的圆锥【51nod】【BSG白山极客挑战赛】
- Bigbluebutton中文乱码问题
- Bigbluebutton安装过程
- [置顶] Android自定义View(二、深入解析自定义属性)
- Android自定义View(二、深入解析自定义属性)
- 蓝桥杯国赛前一周深夜思索
- 辛星浅析yaml
- 使用GSON解析一个复杂的json