48. Rotate Image(重要)
来源:互联网 发布:湖南大学软件学院 编辑:程序博客网 时间:2024/06/06 13:04
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?
/* * clockwise rotate * first reverse up to down, then swap the symmetry * 1 2 3 7 8 9 7 4 1 * 4 5 6 => 4 5 6 => 8 5 2 * 7 8 9 1 2 3 9 6 3*/void rotate(vector<vector<int> > &matrix) { reverse(matrix.begin(), matrix.end()); for (int i = 0; i < matrix.size(); ++i) { for (int j = i + 1; j < matrix[i].size(); ++j) swap(matrix[i][j], matrix[j][i]); }}/* * anticlockwise rotate * first reverse left to right, then swap the symmetry * 1 2 3 3 2 1 3 6 9 * 4 5 6 => 6 5 4 => 2 5 8 * 7 8 9 9 8 7 1 4 7*/void anti_rotate(vector<vector<int> > &matrix) { for (auto vi : matrix) reverse(vi.begin(), vi.end()); for (int i = 0; i < matrix.size(); ++i) { for (int j = i + 1; j < matrix[i].size(); ++j) swap(matrix[i][j], matrix[j][i]); }}
0 0
- 48. Rotate Image(重要)
- [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
- 今天是新的一天j
- css 更改鼠标为手状样式
- Volley 实例DEMO
- android实现登录发送短信验证码或者语音验证码以及一个倒计时的内部类
- vs edmx无法从数据库更新模型的解决方案
- 48. Rotate Image(重要)
- 程序3-3 蛇形填数
- oracle行转列
- VirtualBox(启动失败:intel_rapl no valid rapl domains found in package 0 error VirtualBox)
- Full gc的触发条件
- 嵌入式学习-linux系统-lesson3-文件系统的制作及nfs挂载
- 手机端输入框过滤表情JS代码
- JS的冒泡函数
- Java快速排序的具体实现