Rotate Image
来源:互联网 发布:提词器软件 mac 编辑:程序博客网 时间:2024/05/16 15:15
题目原型:
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度,分析得,先交换i,j即:A[i][j]与A[j][i]交换,然后逆置每行。
public void rotate(int[][] matrix){int i = 0;int j = 0;int k = 0;int temp = 0;for(i = 0;i<matrix.length;i++){for(j=i;j<matrix[0].length;j++){temp = matrix[i][j];matrix[i][j] = matrix[j][i];matrix[j][i] = temp;}}for(i=0;i<matrix.length;i++){for(j=0,k=matrix[0].length-1;j<k;j++,k--){temp = matrix[i][j];matrix[i][j] = matrix[i][k];matrix[i][k] = temp;}}}
0 0
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- 微信红包“昙花一现”?看传统企业中兴如何玩转“微信红包”
- poj 1952 DP
- AR增强现实在现实生活中的应用
- MIME Type介绍
- myEclipse 打不开struts-config.xml 报Could not open the editor: An unexpected exception was thrown 错误(转载)
- Rotate Image
- IIS7发布MVC出现的坑爹问题
- 【Unity3D编程】简易时钟制作
- 简说LINUX 下chmod|chown|chgrp和用法和区别
- VC++函数参数压栈顺序
- 使用TextView/EditText应该注意的地方
- ios--常用控件尺寸大集合
- 【IOS学习】之四、协议,委托,分类粗解
- window.location.href的用法