# -*- 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# 客户端发送http请求代码 (c/s)

    public class RestClient { private string BaseUri; public RestClient(string baseUri) { this.BaseUri = ...

  2. C# sql Helper

    using System; using System.Collections; using System.Collections.Generic; using System.Configuration ...

  3. Linux系统编程(3)——文件与IO之fcntl函数

    linux文件I/O用:open.read.write.lseek以及close函数实现了文件的打开.读写等基本操作.fcntl函数可以根据文件描述词来操作文件. 用法: int fcntl(int ...

  4. wget命令3(转载)

    Wget下载终极用法和15个详细的例子 Wget是一种很好用的因特网下载工具,他具有的很多特性是其他工具所不能比拟的,再者他是一个轻量级可配置的下载工具. 本文结合例子介绍Windows下wget的多 ...

  5. 【转】C/C++程序员应聘常见面试题深入剖析

    1.引言 本文的写作目的并不在于提供C/C++程序员求职面试指导,而旨在从技术上分析面试题的内涵.文中的大多数面试题来自各大论坛,部分试题解答也参考了网友的意见­. 许多面试题看似简单,却需要深厚的基 ...

  6. Quartz 开源的作业调度框架

    Quartz 是一个开源的作业调度框架,它完全由 Java 写成,并设计用于 J2SE 和 J2EE 应用中.它提供了巨大的灵活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度.本 ...

  7. flappy bird游戏源代码揭秘和下载

    转:http://blog.csdn.net/touchsnow/article/details/19071961 背景: 最近火爆全球的游戏flappy bird让笔者叹为观止,于是花了一天的时间山 ...

  8. Eclipse/IDEA中使用Maven创建Web项目报错

    Eclipse中的错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp-1.0.jar:R ...

  9. PCI、PCIE配置空间的訪问(MCFG,Bus,Device,Funtion)

    一般来说,在x86平台上,有两大类方式能够訪问这一区间的寄存器,   1,配置机制1#或者配置机制2#   訪问时借助in/out指令.请注意,这样的方式有别于一般的in/out指令訪问PCI的IO空 ...

  10. DropDownList 绑定数据后 插入一条不属于表中的数据

    ddlFGiftId.DataSource = dtGift; ddlFGiftId.DataTextField = "FGiftName"; ddlFGiftId.DataVal ...