leetcode:将一维数组转变成二维数组
作者:互联网
新年好呀!
代码:
class Solution:
def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]:
if len(original) != m * n:
return []
ans = [[0] * n for _ in range(m)]
for i in range(len(original)):
r = i // n
c = i % n
ans[r][c] = original[i]
return ans
标签:return,数组,int,List,len,original,一维,ans,leetcode 来源: https://blog.csdn.net/weixin_40986490/article/details/122268854