Leetcode 2132 Solution
This article provides solution to leetcode question 2132 (convert-1d-array-into-2d-array)
Access this page by simply typing in "lcs 2132" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/convert-1d-array-into-2d-array
Solution
class Solution:
def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]:
if m * n != len(original):
return []
ans = [[0 for _ in range(n)] for _ in range(m)]
for i in range(m):
for j in range(n):
ans[i][j] = original[i * n + j]
return ans