LC2022 - Convert 1D Array into 2D Array (EASY)#

This is the solution for Leetcode Problem 2022 - Convert 1D Array into 2D Array.

 1"""Solution to Leetcode 2022 - 2022
 2
 3Link : https://leetcode.com/problems/convert-1d-array-into-2d-array/
 4Level: easy
 5"""
 6
 7
 8class Solution:
 9    def __init__(self, *args, **kwargs):
10        """Instantiates the solution object"""
11        self.args = args
12        self.kwargs = kwargs
13
14    def solve(self, *args, **kwargs):
15        """This implements the main solution"""
16        raise NotImplementedError("This solution is not yet implemented.")
17
18    def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]:
19        array = []
20        # check if the rearrangement is possible.
21        if (m * n) != len(original):
22            return array
23        row = []
24        for ix, item in enumerate(original):
25            row.append(item)
26            if (ix + 1) % n == 0:
27                array.append(row)
28                row = []
29
30        return array