48. Rotate Image
来源:互联网 发布:java thread 回调 编辑:程序博客网 时间:2024/05/19 11:38
- Rotate Image My Submissions QuestionEditorial Solution
Total Accepted: 65856 Total Submissions: 190558 Difficulty: Medium
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?
之前做了个数组的旋转,用了额外的矩阵空间,
而这个题是不开辟额外空间的。
class Solution {public: void rotate(vector<vector<int>>& matrix) { int n=matrix.size(); if(n==0)return; for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ swap(matrix[i][j],matrix[j][i]); } } for(int j=0;j*2<n-1;j++){ for(int i=0;i<n;i++){ swap(matrix[i][j],matrix[i][n-1-j]); } } }};
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
- Java Socket网络编程的经典例子
- Java IO流
- Centos7下的systemctl命令与service和chkconfig
- android ListView 几个重要属性
- nyoj 925 国王的烦恼
- 48. Rotate Image
- Android UI基础 --基本控件
- avrdude下载错误及解决
- 数据缓存——NSKeyedArchiver归档(NSCoding)
- 关键字const
- JAVA用双栈实现队列,纪念我挂掉的第一次腾讯面试题
- Android中的Handler和AsyncTask的区别
- [arr firstObject] 和 arr[0] 的区别
- Android中关联源码遇到的问题