Lintcode161 Rotate Image solution 题解
来源:互联网 发布:cn域名 国外空间 编辑:程序博客网 时间:2024/06/11 10:53
【题目描述】
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。
【题目链接】
www.lintcode.com/en/problem/rotate-image/
【题目解析】
在计算机图像处理里,旋转图片是很常见的,由于图片的本质是二维数组,所以也就变成了对数组的操作处理,翻转的本质就是某个位置上数移动到另一个位置上,比如用一个简单的例子来分析:
1 2 3 7 4 1
4 5 6 --> 8 5 2
7 8 9 9 6 3
对于90度的翻转有很多方法,一步或多步都可以解,我们先来看一种直接的方法,对于当前位置,计算旋转后的新位置,然后再计算下一个新位置,第四个位置又变成当前位置了,所以这个方法每次循环换四个数字,如下所示:
1 2 3 7 2 1 7 4 1
4 5 6 --> 4 5 6 --> 8 5 2
7 8 9 9 8 3 9 6 3
【参考答案】
www.jiuzhang.com/solutions/rotate-image/
阅读全文
0 0
- Lintcode161 Rotate Image solution 题解
- LeetCode题解:Rotate Image
- LeetCode48. Rotate Image题解
- Lintcode8 Rotate String solution 题解
- Lintcode170 Rotate List solution 题解
- 【LeetCode】【Python题解】Rotate Image
- leetcode题解-48. Rotate Image
- Leetcode题解-48. Rotate Image
- LeetCode 题解(30): Rotate Image
- LeetCode题解——Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- JavaScript基础
- 水仙花数
- CTF writeup之pwn2own warehouse
- 算法 动态规划
- 如何写出好代码(一)
- Lintcode161 Rotate Image solution 题解
- 爬虫爬取完本小说
- HDU
- 【Flashback】启用Flashback Database闪回数据库功能
- C++多继承
- css3中的滤镜特效
- Android assets中json文件的使用
- 分治策略 & 最大子数组的问题
- Naive Bayes(朴素贝叶斯)