class Solution:
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
m = len(nums)
n = len(nums[0])
if m * n != r * c:
return nums
new_nums = [[0] * c for i in range(r)]
L = []
for j in range(m):
L += nums[j]
for row in range(r):
for col in range(c):
new_nums[row][col] = L[row * c +col]
return new_nums
leetcode - 566 - 重塑矩阵
最新推荐文章于 2022-10-15 15:24:13 发布