• 题目描述:把一个二维数组顺时针旋转90度;

  • 思路:

  1. 对于数组每一圈进行旋转,使用m控制圈数;
  2. 每一圈的四个元素顺时针替换,可以直接使用Python的解包,使用k控制每一圈的具体元素;
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
n = len(matrix)
m = 0
while m <= n / 2:
k = m
while k < n - 1 - m:
matrix[m][k], matrix[k][n-1-m], matrix[n-1-m][n-1-k], matrix[n-1-k][m] = \
matrix[n-1-k][m], matrix[m][k], matrix[k][n-1-m], matrix[n-1-m][n-1-k]
k += 1
m += 1

Python 解leetcode:48. Rotate Image的更多相关文章

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

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

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

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

  3. LeetCode 48. Rotate Image(旋转图像)

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

  4. Python 解LeetCode:Intersection of Two Arrays

    最近,在用解决LeetCode问题的时候,做了349: Intersection of Two Arrays这个问题,就是求两个列表的交集.我这种弱鸡,第一种想法是把问题解决,而不是分析复杂度,于是写 ...

  5. LeetCode 48 Rotate Image(2D图像旋转问题)

    题目链接: https://leetcode.com/problems/rotate-image/?tab=Description   Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...

  6. [leetcode 48] rotate image

    1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...

  7. C#解leetcode 189. Rotate Array

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

  8. leetCode 48.Rotate Image (旋转图像) 解题思路和方法

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

  9. Python 解LeetCode:671. Second Minimum Node In a Binary Tree

    题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...

随机推荐

  1. Spring注解驱动——组件注册系列

    1.@Configuration 从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被Annot ...

  2. 使用Flask设计带认证token的RESTful API接口

    大数据时代 Just a record. 使用Flask设计带认证token的RESTful API接口[翻译] 上一篇文章, 使用python的Flask实现一个RESTful API服务器端  简 ...

  3. Echarts-复杂关系图(源码)

    关系图: 代码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script type=& ...

  4. JavaWeb_(Mybatis框架)MyBatis Generator简单入门

    官方文档 传送门 下载地址 传送门 MyBatis Generator(MBG)简介: MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为 ...

  5. JavaEE项目开发所需要的包(Struts2+Spring5+Hibernate5)

    在这里我只整理了轻量级JavaEE项目开发所需的包 @Auther MrZhangxd 2019-04-29  23:07:21 链接:https://pan.baidu.com/s/16I4KYah ...

  6. MapReduce On Yarn的配置详解和日常维护

    MapReduce On Yarn的配置详解和日常维护 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MapReduce运维概述 MapReduce on YARN的运维主要是 ...

  7. mac安装mysql数据库及配置环境变量

    mac安装mysql数据库及配置环境变量 mac安装mysql数据库及配置环境变量 原文文链接:https://blog.csdn.net/qq_36004521/article/details/80 ...

  8. v-on绑定特性命名带小横杠 ‘-’与props属性中变量怎么对应

    特性命名问题: 矛盾点一:html的特性不区分大小写 矛盾点二:Vue中除了模板命名,其他命名不允许出现小横杠 ‘-’ 在js文件内,命名为驼峰式,camerCase,进入html文件,自动转换成短横 ...

  9. android ONVIF 组播探测在线摄像机

    http://blog.csdn.net/ghostyu/article/details/8182516 Android的Wifi,默认情况下是不接受组播的,见:http://developer.an ...

  10. kubectl 之 patch 命令

    patch命令 kubectl patch — Update field(s) of a resource using strategic merge patch Synopsis kubectl p ...