48. Rotate Image
来源:互联网 发布:淘宝开店收费吗2016 编辑:程序博客网 时间:2024/06/05 09:02
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?
思路: 先将数组以中间行为标准翻转,然后再以主对角线为标准交换对应元素。
时间复杂度:O(N*N)
空间复杂度: O(1)
<span style="font-size:14px;">public class Solution { public void rotate(int[][] matrix) { int n=matrix.length; int temp; //swap row i and n-1-i for(int i=0;i<n/2;i++){ for(int j=0;j<n;j++){ temp=matrix[i][j]; matrix[i][j]=matrix[n-1-i][j]; matrix[n-1-i][j]=temp; } } // for(int i=1;i<n;i++){ for(int j=0;j<i;j++){ temp=matrix[i][j]; matrix[i][j]=matrix[j][i]; matrix[j][i]=temp; } } }}</span>
0 0
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- leetcode 48. Rotate Image
- Leetcode 48. Rotate Image
- LeetCode 48. Rotate Image
- 算法---直接插入排序
- 怎样学习图像处理技术?(二)
- iOS加载网络图片,删除本地或者网络图片
- 静态数据成员和静态成员函数用法精髓
- Max Sum
- 48. Rotate Image
- 自定义UIPickerView修改显示样式
- hdu3929 容斥+扩展Lucas定理
- Leetcode 397. Integer Replacement (Easy) (cpp)
- 多态特性---主板设计模式
- hive中if和coalesce 去除null值,case when
- 面向对象_通过JDK的帮助文档学习Math类的随机数功能
- Java算法之输出“菱形”
- Android Studio 2.2 尝鲜的代价