Skip to content
LC-2022 Easy LeetCode

2022. Convert 1D Array Into 2D Array

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 72% Topics: Array, Matrix, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(m * n)
# Space: O(1)

class Solution(object):
    def construct2DArray(self, original, m, n):
        """
        :type original: List[int]
        :type m: int
        :type n: int
        :rtype: List[List[int]]
        """
        return [original[i:i+n] for i in xrange(0, len(original), n)] if len(original) == m*n else []

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions