Skip to content

Commit

Permalink
Create convert-1d-array-into-2d-array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Oct 3, 2021
1 parent 83872b0 commit 5cd6311
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Python/convert-1d-array-into-2d-array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 []

0 comments on commit 5cd6311

Please sign in to comment.