Skip to content

Commit 5cd6311

Browse files
authored
Create convert-1d-array-into-2d-array.py
1 parent 83872b0 commit 5cd6311

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Time: O(m * n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def construct2DArray(self, original, m, n):
6+
"""
7+
:type original: List[int]
8+
:type m: int
9+
:type n: int
10+
:rtype: List[List[int]]
11+
"""
12+
return [original[i:i+n] for i in xrange(0, len(original), n)] if len(original) == m*n else []

0 commit comments

Comments
 (0)