leetcode | 图片的旋转(顺时针90°) | Python
2017-06-05 22:18
453 查看
题目:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
res = []
while matrix[0]:
tmp = []
for row in matrix:
tmp.insert(0,row.pop(0)) #list.insert(position,value)
res.append(tmp)
for i in range(len(matrix)): #这里,必须对matrix中的每行都进行修改,才能对其重新赋值,不能直接:matrix=res
matrix[i] = res[i]
s = Solution()
matrix = [[1,2],[3,4]]
s.rotate(matrix)
print matrix
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
res = []
while matrix[0]:
tmp = []
for row in matrix:
tmp.insert(0,row.pop(0)) #list.insert(position,value)
res.append(tmp)
for i in range(len(matrix)): #这里,必须对matrix中的每行都进行修改,才能对其重新赋值,不能直接:matrix=res
matrix[i] = res[i]
s = Solution()
matrix = [[1,2],[3,4]]
s.rotate(matrix)
print matrix
相关文章推荐
- Python将图片顺时针旋转90°
- php图像旋转,图片旋转(逆时针90或者顺时针90)
- php图像旋转,图片旋转(逆时针90或者顺时针90)
- LeetCode -- 顺时针旋转图片90度
- leetcode Rotate list (链表旋转)的python实现
- JS点击顺时针旋转90°
- leetcode之图片(矩阵)旋转
- 顺时针旋转图片90度(算法)
- [leetcode]Rotate Image, Matrix tranposition, matrix rotation 90 degree @ Python
- iOS自定义相机截取图片旋转90°的问题
- 将矩阵顺时针旋转90度 leetCode:Rotate Image
- iOS 对Image图片本身进行旋转0,90,180,270
- MTK平台下图片旋转90的函数
- 顺时针旋转N*N阶矩阵储存的图片
- 三星手机拍照,上传照片或者下载导致图片旋转90°的解决办法。
- 图片镜像水平翻转,垂直翻转以及顺时针,逆时针旋转
- python图片旋转
- Leetcode:Rotate Image 旋转图片
- python简单实现旋转图片的方法
- 1.6 给出一张图片,表示为NXN的居然,每个像素点为4字节。写一个函数实现将这张图片旋转90°。