原题地址:https://oj.leetcode.com/problems/rotate-image/

题意:

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

解题思路:先将矩阵转置,然后将矩阵的每一行翻转,就可以得到所要求的矩阵了。

代码:

class Solution:
# @param matrix, a list of lists of integers
# @return a list of lists of integers
def rotate(self, matrix):
n = len(matrix)
for i in range(n):
for j in range(i+1, n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for i in range(n):
matrix[i].reverse()
return matrix

[leetcode]Rotate Image @ Python的更多相关文章

  1. [leetcode]Rotate List @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...

  2. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  3. [LeetCode]题解(python):061-Rotate list

    题目来源 https://leetcode.com/problems/rotate-list/ Given a list, rotate the list to the right by k plac ...

  4. [LeetCode]题解(python):048-Rotate Image

    题目来源 https://leetcode.com/problems/rotate-image/ You are given an n x n 2D matrix representing an im ...

  5. [LeetCode] Rotate Array 旋转数组

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  6. [LeetCode] Rotate List 旋转链表

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  7. [LeetCode] Rotate Image 旋转图像

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

  8. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

  9. [LeetCode]题解(python):120 Triangle

    题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...

随机推荐

  1. 链表用途&&数组效率&&链表效率&&链表优缺点

    三大数据结构的实现方式 数据结构 实现方式 栈  数组/单链表 队列  数组/双端链表 优先级队列 数组/堆/有序链表 双端队列 双向链表 数组与链表实现方式的比较 数组与链表都很快 如果能精确预测栈 ...

  2. 一个页面从输入 URL 到页面加载显示完成,这个过程中都发生了什么?

    分为4个步骤: 1)  当发送一个 URL 请求时,不管这个 URL 是 Web 页面的 URL 还是 Web 页面上每个资源的 URL,浏览器都会开启一个线程来处理这个请求,同时在远程 DNS 服务 ...

  3. Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学

    E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...

  4. 【转】InitializingBean的作用

    原文链接:http://blog.csdn.net/maclaren001/article/details/37039749 最近工作需要得到sping中的每个事物需要执行的sql,称机会简单研究了一 ...

  5. mysql慢查询日志功能的使用

    作用:mysql慢查询日志可监控有效率问题的SQL .. 一.开启mysql慢查询日志功能 1.查看是否开启 未使用索引的SQL记录日志查询 mysql> show variables like ...

  6. spring cloud 学习(5) - config server

    分布式环境下的统一配置框架,已经有不少了,比如百度的disconf,阿里的diamand.今天来看下spring cloud对应的解决方案: 如上图,从架构上就可以看出与disconf之类的有很大不同 ...

  7. android流量统计

    研究过一段时间的android流量统计发个自己的总结帖 1 android有一个TrafficStats类可以直接获取 总接受流量TrafficStats.getTotalRxBytes(), 总发送 ...

  8. Android深入浅出之Binder机制(转)

    Android深入浅出之Binder机制 一 说明 Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交互的.所以搞明白B ...

  9. C#——性能计数器

    简要Windows性能监视器: 打开Windows性能监视器的步骤如下: 开始→运行→perfmon→确定 在这里我们可以选择添加我们要监控的计数器,比如:cpu使用率.内存使用量等,作为asp.ne ...

  10. JSONPATH使用方法

    如下的json: { "store": { "book": [ { "category": "reference", & ...