leetcode

Description:

leetcode-566

Submission:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class :
def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]:
h = len(nums)
w = len(nums[0])
if (r*c != h*w):
return nums
else:
ans = []
for _ in range(r):
ans.append([0] * c)
for i in range(h):
for j in range(w):

ans[(i*w+j)//c][(i*w+j)%c] = nums[i][j]
return ans

Acceptance:

ac