Python 解leetcode:48. Rotate Image
题目描述:把一个二维数组顺时针旋转90度;
思路:
- 对于数组每一圈进行旋转,使用m控制圈数;
- 每一圈的四个元素顺时针替换,可以直接使用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的更多相关文章
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- Python 解LeetCode:Intersection of Two Arrays
最近,在用解决LeetCode问题的时候,做了349: Intersection of Two Arrays这个问题,就是求两个列表的交集.我这种弱鸡,第一种想法是把问题解决,而不是分析复杂度,于是写 ...
- LeetCode 48 Rotate Image(2D图像旋转问题)
题目链接: https://leetcode.com/problems/rotate-image/?tab=Description Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...
- [leetcode 48] rotate image
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
- 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 ...
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- Python 解LeetCode:671. Second Minimum Node In a Binary Tree
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
随机推荐
- WEB测试重点及视频教程
WEB测试重点如下: 1.WEB测试基础-2.理解网络协议-3.HTTP协议详解-4.WEB前段分析-5WEB安全性测试-6.WEB兼容性及可用性测试. 1.通常需要承受长时间的大量操作,因此web项 ...
- java集合类-集合框架体系
集合框架体系 集合框架体系是由Collection.Map和 Iterator(迭代器) 实线边框的是实现类,折线边框的是抽象类,而点线边框的是接口 Collection体系 Set接口:元素无序且不 ...
- SpringMVC指定webapp的首页
webapp的首页指的是http://localhost:8080/ 方法一 追加一个[/]URI的请求方法 @Controller public class WelcomeController { ...
- tar 命令出现 Cowardly refusing to create an empty archive 问题详解
错误提示的字面意思是,系统惴惴不安地拒绝执行创建一个空压缩包的任务.检查tar命令的语法!!!参考:https://blog.csdn.net/deniro_li/article/details/54 ...
- ROS Topic 常用指令
rostopic list rosnode list一樣,就是列出目前運行中的topic有哪些. rostopic echo <topic_name> 接下來這個指令比較重要啦,就是去監聽 ...
- jinja2-宏,include, import
一 宏 宏类似常规编程语言中的函数.它们用于把常用行为作为可重用的函数,取代 手动重复的工作.如果宏在不同的模板中定义,你需要首先使用 import,比如 {% macro input(name, v ...
- Linux设备驱动程序 之 中断
中断 中断使得硬件可以发出通知给处理器,本质上是一种特殊的电信号,由硬件设备发向处理器,处理器接收到中断后,会马上向操作系统反应此信号的到来,然后就由操作系统负责处理这些新来的数据:硬件设备生成中断并 ...
- eclipse java
1Java:Java是由Sun Microsystems公司推出的Java面向对象程序设计语言和Java平台的总称. 2.Eclipse:Eclipse 是一个开放源代码的.基于Java的可扩展开发平 ...
- [转][echarts]地图轮播
代码片断: 来自:https://blog.csdn.net/qq_36947128/article/details/90899564 function Play(){ chart.dispatchA ...
- 前端中关于HTML标签的属性for的理解
First:<label>的说明:1.<label>标签为input元素定义标注(标识)2.label元素不会像用户呈现任何特殊的效果,仅作为显示扩展:不过,它为鼠标用户改进了 ...