# -*- 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. C# DateTime类,TimeSpan类

    DateTime类是.Net中用于处理时间类型数据的. 一.字段 MaxValue 表示 DateTime 的最大可能值.此字段为只读. MinValue     表示 DateTime 的最小可能值 ...

  2. Red and Black(BFS or DFS) 分类: dfs bfs 2015-07-05 22:52 2人阅读 评论(0) 收藏

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  3. MongoDb Windows linux平台环境及主流编程语言驱动安装同时配置mongoDb的远程连接

    <一,>MongoDB 简介篇Ruiy; MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种.它在许多场景下可用于替代传统的关系型数据库或键/值 ...

  4. hibernate多对一的操作解析

    在hibernate的关联操作中有很多关系,其中多对一关系是最常见的.我们看这两个表. 这里有部门表和员工表. 那么我们可以这么说一个部门可以有多个员工.这就是1对多的关系.这是我们站在部门表的角度上 ...

  5. 二十六、Jcreator使用初步

    摘自http://blog.csdn.net/liujun13579/article/details/7751464 二十六.Jcreator使用初步 Jcreator是一个小巧灵活的Java开发工具 ...

  6. 模块工具类--utils

    File: js\utils.js/** * 模块工具类,用来初始化各模块视图.自定绑定事件以及其他辅助功能等 * @class Utils */Utils = (function() { var i ...

  7. ffmpeg常用参数一览

    基本选项: -formats 输出所有可用格式 -f fmt 指定格式(音频或视频格式) -i filename 指定输入文件名,在linux下当然也能指定:0.0(屏幕录制)或摄像头 -y 覆盖已有 ...

  8. AAC ADTS解析

    1.ADTS ADTS全称是(Audio Data Transport Stream),是AAC的一种十分常见的传输格式. 一般的AAC解码器都需要把AAC的ES流打包成ADTS的格式,一般是在AAC ...

  9. Opencv--HoughCircles源码剖析

    图形可以用一些参数进行表示,标准霍夫变换的原理就是把图像空间转换成参数空间(即霍夫空间),例如霍夫变换的直线检测就是在距离-角度空间内进行检测.圆可以表示成: (x-a)2+(y-b)2=r2     ...

  10. C# Winform中执行post操作并获取返回的XML类型的数据

    /// <summary> /// 返回指定日期的订单数据 /// </summary> /// <param name="StartDate"> ...