leetcoed Rotate Image
来源:互联网 发布:软件项目管理招聘 编辑:程序博客网 时间:2024/05/03 00:44
题目链接
思路:
找规律,旋转的规律就是i,j的下一个点是j,n-i。其中n行数减一。
这样进行4次转一圈旋转了一个像素。。
再观察出需要用哪些像素做起始点然后开始旋转。。
public class Solution { int [][]matrix; int n; public void rotate(int[][] matrix) { this.matrix=matrix; n=matrix.length-1; for(int i=0;i<=n/2;i++) { for(int j=i;j<n-i;j++) { swap(i, j); } } } public void swap(int i,int j) { int src=matrix[i][j]; int temp; int nexti; int nextj; for(int k=0;k<4;k++) { nexti=j; nextj=n-i; temp=matrix[nexti][nextj]; matrix[nexti][nextj]=src; src=temp; i=nexti; j=nextj; } }}
0 0
- leetcoed 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
- 选择法对数组进行排序
- 界面优美开源iPhone App编译步骤
- jinfo工具
- JQuery插件:表单数据校验
- static 与 const 的作用总结
- leetcoed Rotate Image
- 扫描线法填充多边形
- oracle 7
- 广播broadcast常识1
- android VideoView实现视频的播放
- HDOJ 1849 Rabbit and Grass(尼姆博奕)
- 快速排序法
- c# 读取xml常用方法
- NodeJS 错误处理最佳实践