【发布时间】:2018-03-08 01:31:28
【问题描述】:
我正在解决一个问题,它以数字、行、列作为参数并返回大小为行 x 列的结果矩阵。
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
count = 0
i = j = 0
m = [[0]*c]*r
for row in nums:
for val in row:
if j < c and i < r:
print(val,m[i][j], i, j)
m[i][j] = val
print(val,m[i][j], i, j)
count += 1
j += 1
if j == c:
i += 1
j = 0
if count == (r*c):
return m
else:
return nums
当我测试像 ([[1,2],[3,4]], 4, 1) 这样的输入时,它会生成输出 [[4],[4],[4],[4]] 而不是[[1],[2],[3],[4]]
【问题讨论】:
-
请edit你的问题标题是有意义的。它应该以对在搜索结果列表中查看它的未来读者有用的方式描述您提出的问题或问题。您当前的标题具有零意义。谢谢。