leetcode 48. Rotate Image
2016-03-28 13:23
351 查看
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?
void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
int offset = 0;
while (2*(offset+1) <= matrixRowSize)
{
for (int i = offset; i < matrixRowSize - offset-1; i++)
{
int aa[4] = { matrix[offset][i], matrix[i][matrixColSize - 1 - offset],
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i], matrix[matrixRowSize - 1 - i][offset] };
matrix[offset][i] = aa[3];
matrix[i][matrixColSize - 1 - offset] = aa[0];
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i] = aa[1];
matrix[matrixRowSize - 1 - i][offset] = aa[2];
}
offset++;
}
}
accepted
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
int offset = 0;
while (2*(offset+1) <= matrixRowSize)
{
for (int i = offset; i < matrixRowSize - offset-1; i++)
{
int aa[4] = { matrix[offset][i], matrix[i][matrixColSize - 1 - offset],
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i], matrix[matrixRowSize - 1 - i][offset] };
matrix[offset][i] = aa[3];
matrix[i][matrixColSize - 1 - offset] = aa[0];
matrix[matrixRowSize - 1 - offset][matrixColSize - 1 - i] = aa[1];
matrix[matrixRowSize - 1 - i][offset] = aa[2];
}
offset++;
}
}
accepted
相关文章推荐
- platform驱动之probe函数
- 透明状态栏和透明导航栏
- 写了几年代码了,苦苦追寻,应该沉淀下来了,好好研究。net底层框架,以及较好的分层框架
- 【作业】第六周作业
- 【作业】第五周作业
- 九九乘法表
- 【dji sdk】mobile sdk 视频部分
- 【作业】第四周作业
- struct和typedef struct
- win7系统激活最简单方法
- Entity Framework Utility .ttinclude File
- CakePHP文件下载
- 百万级数据库优化方案
- PAT-1014. 福尔摩斯的约会 (20)
- 各种caffe版本的网址及配置资料
- 汇编学习4:寄存器之CPU工作原理
- java 反编译 class文件 jad eclipse乱码
- 钩子(hook)编程
- http
- JFinal学习--05Render