# -*- coding: utf8 -*-
'''
__author__ = 'dabay.wang@gmail.com' 48: Rotate Image
https://leetcode.com/problems/rotate-image/ You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Could you do this in-place? === Comments by Dabay===
画一个图,先按照左上到右下的斜线翻转,然后再按照竖对称轴翻转。
''' class Solution:
# @param matrix, a list of lists of integers
# @return nothing (void), do not return anything, modify matrix in-place instead.
def rotate(self, matrix):
dimension = len(matrix)
for i in xrange(dimension):
for j in xrange(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for i in xrange(dimension):
for j in xrange(dimension/2):
matrix[i][j], matrix[i][dimension-1-j] = matrix[i][dimension-1-j], matrix[i][j] def main():
sol = Solution()
matrix = [
[1,2],
[3,4]
]
sol.rotate(matrix)
print matrix if __name__ == "__main__":
import time
start = time.clock()
main()
print "%s sec" % (time.clock() - start)

[Leetcode][Python]48: Rotate Image的更多相关文章

  1. Python 解leetcode:48. Rotate Image

    题目描述:把一个二维数组顺时针旋转90度: 思路: 对于数组每一圈进行旋转,使用m控制圈数: 每一圈的四个元素顺时针替换,可以直接使用Python的解包,使用k控制每一圈的具体元素: class So ...

  2. 【LeetCode】48. Rotate Image 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 【一天一道LeetCode】#48. Rotate Image

    一天一道LeetCode系列 (一)题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 ...

  4. 【LeetCode】48. Rotate Image

    Difficulty:medium  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/rotate-image/ ...

  5. LeetCode OJ 48. Rotate Image

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  6. 【LeetCode】48. Rotate Image (2 solutions)

    Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...

  7. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  8. [LeetCode] 48. Rotate Image 旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  9. 【LeetCode】61. Rotate List 解题报告(Python)

    [LeetCode]61. Rotate List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

随机推荐

  1. 并行编译加快VS C++项目的编译速度

    最近编译的项目都比较大,话说自己的电脑配置还行,但编译所花的时间还是很长,遇到需要重新编译整个项目的时候真的有回宿舍睡一觉的冲动.昨天一不小心被我发现了一款软件Xoreax IncrediBuild ...

  2. C# System.Uri类_获取Url的各种属性_文件名_参数_域名_端口等等

    System.Uri类用于处理Uri地址信息,常用到它的地方有,相对Uri地址转绝对Uri地址,获取Uri的某部分信息等等,可以说是一个非常有用的类. 一.属性 AbsolutePath 获取 URI ...

  3. WPF 利用子线程弹出子窗体的研究

    一般来说子线程都是用来处理数据的,主窗体用来实现展现,但是有些时候我们希望子窗体实现等待效果,遮挡主窗体并使主窗体逻辑正常进行,这个业务需求虽然不多,但是正好我们用到了,于是我打算把研究成果写在这了. ...

  4. grep搜索当前目录和递归搜索子目录中文本文件的特定pattern

    一般在windows上文本编辑器notepad++,UE这些都有这些功能,Linux下就换了一种方式,用grep来完成文件中信息查找的方式. grep -R -n --include="*. ...

  5. JSON 数字排序 多字段排序

    原文http://bbs.csdn.net/topics/390594744?page=1#post-395599672 //排序数组 function SortBy(field, reverse, ...

  6. expect set timeout -1 永不超时

    . ~/.bash_profile passwd='xxx' expect <<! set timeout -1 spawn rsync -avH /webapps/Seeyon/A8/b ...

  7. mysql 存储过程 事务处理

    BEGIN ; ; START TRANSACTION; #这边放sql语句,涉及到的表必须都为InnoDB THEN ROLLBACK; ELSE COMMIT; END IF; END

  8. UESTC_握手 CDOJ 913

    握手 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status ...

  9. OpenStack 部署总结之:在CentOS 6.5上使用RDO单机安装icehouse(Ml2+GRE)

    本文主要介绍怎样在CentOS6.5上通过RDO来安装icehouse,因为安装的过程中涉及的软件较多,以及依赖关系比較复杂,建议使用一个全新的操作系统来进行安装. 安装步骤详细例如以下 (1)安装操 ...

  10. sqlite数据库读写在linux下的权限问题

    近期在学linux,恰巧有个php项目要做.于是配置好环境打算在linux下做. 无奈站点执行后一片空白.经过调试发现是sqlite数据库的问题. 安装sqlite扩展 apt-get install ...