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
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
随机推荐
- psexec局域网执行远程命令
执行远程命令的工具psexec.exe 下载 一.首先,被控制机器必须开启ipc$,以及admin$,否则无法执行 开启ipc$ net share IPC$ 开启admin$ net share A ...
- 下载、配置全新的eclipse
1.https://www.eclipse.org/downloads/ 2.确保安装配置了JDK,打开eclipse-inst-win64.exe,让eclipse installer程序UPDAT ...
- 1-4CMYK色彩模式
http://www.missyuan.com/thread-350717-1-1.html CMYK也称作印刷色彩模式,顾名思义就是用来印刷的. 只要是在印刷品上看到的图像,就是CMYK模式表现的 ...
- Golang的文件处理方式-常见的读写
在 Golang 语言中,文件使用指向 os.File 类型的指针来表示的,也叫做文件句柄.注意,标准输入 os.Stdin 和标准输出 os.Stdout ,他们的类型都是 *os.File 哟.在 ...
- centos7的网络配置参考
<鸟哥的Linux私房菜>中的相关介绍和配置:http://linux.vbird.org/linux_basic/0610hardware.php 修改链接(connection)的名字 ...
- 在Ubuntu18.04上安装Nvidia驱动
拿到了一台新机子,带显卡的那种,当然是各种倒腾了!于是我又一天装了三遍机子来进行各种尝试熟悉配置啥的. 所以首先是在裸机上安装Nvidia驱动. 环境:Ubuntu18.04 刚安装完系统,当然是把软 ...
- 微信小程序倒计时的方法
timeOut: function(time) { var that = this; var end = new Date(time).getTime(); var Interval = setInt ...
- mysql数据库每个表的备份脚本
对mysql数据库中的每张表进行按日期备份,思想是:先把每张表的表名取出取出,然后通过for循环去对每个表进行按日期备份 [root@ZFVM-APP-- backup]# vim dataname. ...
- exposed beyond app through ClipData.Item.getUri()
Android7.0调用相机时出现新的错误: android.os.FileUriExposedException: file:///storage/emulated/0/photo.jpeg exp ...
- spring boot入门学习---1
1.maven配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...