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
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
随机推荐
- 【线性代数】7-3:对角化和伪逆(Diagonalization and the Pseudoinverse)
title: [线性代数]7-3:对角化和伪逆(Diagonalization and the Pseudoinverse) categories: Mathematic Linear Algebra ...
- SpringAOP配置与使用(示例)
1.pom.xml追加 spring-aspects aspectjrt 为控制器以外的类织入切面 2.新建spring-aop.xml <?xml version="1.0" ...
- Mapreduce-实现webcount代码
参考博文:https://blog.csdn.net/qq_41035588/article/details/90514824 首先安装一个Hadoop-Eclipse-Plugin 方便来对于hdf ...
- PHP 之快递100接口封装
<?php /** * Created by PhpStorm. * User: Yang * Date: 2019/8/23 * Time: 10:38 */ class Kuaidi_Que ...
- 为win10下的linux子系统终端添加powerline
一切按照上一篇完成,如果成功了,你厉害了我的哥,如果不成功,win10安装powerline字体才可以,才可以,才可以 sudo apt install build-essential cmake g ...
- servlet容器:jetty,Tomcat,JBoss
一.几款servlet容器对比:jetty,Tomcat,JBoss 二.JBOSS相关问题解决 1.JBOSS下载安装 2.处理jboss-as-7.1.1.Final与jdk1.8及1.8以上版本 ...
- js中两个感叹号的原理与用法分析
在javascript中有时会看到有两个!!的用法 var foo; alert(!foo);//undifined情况下,一个感叹号返回的是true; alert(!goo);//null情况下,一 ...
- 黑马vue---40、结合Node手写JSONP服务器剖析JSONP原理
黑马vue---40.结合Node手写JSONP服务器剖析JSONP原理 一.总结 一句话总结: 服务端可以返回js代码给script标签,那么标签会执行它,并且可带json字符串作为参数,这样就成功 ...
- DELPHI安卓动态权限申请
DELPHI安卓动态权限申请 安卓8.0以前的版本,只需要给静态权限就可以了,但安卓8.0及以后的版本,还需要运行期用代码动态申请权限. 下面以<蓝牙权限>为例,其他权限类似. Delph ...
- [oracle]oracle表在什么情况下会被锁住(转载)
DML锁又可以分为,行锁.表锁.死锁 行锁:当事务执行数据库插入.更新.删除操作时,该事务自动获得操作表中操作行的排它锁. 表级锁:当事务获得行锁后,此事务也将自动获得该行的表锁(共享锁),以防止其它 ...