566. Reshape the Matrix
来源:互联网 发布:美国仓库淘宝网 编辑:程序博客网 时间:2024/06/09 17:14
class Solution(object):
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
row=len(nums)
colum=len(nums[0])
if row*colum!=r*c:
return nums
else:
tmp=[num for row in nums for num in row]
newarray=[[0 for j in range(c)]for i in range(r)]
for i in range(r):
for j in range(c):
newarray[i][j]=tmp[i*c+j]
return newarray
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
row=len(nums)
colum=len(nums[0])
if row*colum!=r*c:
return nums
else:
tmp=[num for row in nums for num in row]
newarray=[[0 for j in range(c)]for i in range(r)]
for i in range(r):
for j in range(c):
newarray[i][j]=tmp[i*c+j]
return newarray
阅读全文
0 0
- 566. Reshape the Matrix
- 566.Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 沉浸式管理:让你的APP更优雅
- Java反射的作用与用法
- 程序员如何从“职业倦怠”中恢复过来
- 线程、多线程基本原理与两种实现方法
- 原始套接字编程(三)
- 566. Reshape the Matrix
- 路由控制
- Android破解与防破解
- LeetCode Kth Largest Element in an Array
- sass的编译
- 【语言-C++】Win7 64位系统下出现无法启动屏幕键盘的bug
- ORA-01017: invalid username/password; logon denied 解决方案
- echartz常用的图形Demo
- mysql在window机器下的双机备份