Skip to content

Commit c425390

Browse files
committed
Reshape the Matrix
1 parent b3e7c72 commit c425390

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

LeetCode Algorithms/reshape-the-matrix.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
class Solution:
66
def matrixReshape(self, mat, r, c):
77
if (len(mat) * len(mat[0]) == r * c):
8-
oneDimenMat = np.arange(r * c)
9-
n = 0
8+
oneDimenMat = []
109

11-
for i in range(len(mat)):
12-
for j in range(len(mat[0])):
13-
oneDimenMat[n] = mat[i][j]
14-
n += 1
10+
for row in mat:
11+
for num in row:
12+
oneDimenMat.append(num)
1513

16-
newMatrix = np.arange(r * c)
17-
newMatrix = newMatrix.reshape(r, c)
14+
newMatrix = np.arange(r * c).reshape(r, c)
1815
n = 0
1916

2017
for i in range(len(newMatrix)):

0 commit comments

Comments
 (0)