不准访问
- 积分
- 475
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2012-12-19
- 最后登录
- 1970-1-1
|
【解题思路】First we need to know the scale of N to determine use what type to restore this number in order not to overflow, since each pixel uses only 4 bytes, int is enough, we assume that the rotation is anticlockwise. We only need to rotate the upper-left quater "square", replace each quater square iterately, however, this is only the case when N is even, when N is odd, the square has overlap and some pixle might be rotate more than one time. The responding position of pixel in each quater "square" is (i, j), (j, n-i), (n-i, n-j) and (n-j, i), this could be obtained recursively.
【时间复杂度】O(N2)
【空间复杂度】O(1)
【gist link】
https://gist.github.com/6af17484b1fc52138a23.git
---------------OPTional,如果觉得test case比较好,欢迎写出来分享----------------------
【test case】 |
|