Skip to content

Commit be68366

Browse files
committed
Add solution 556
1 parent 0dccaf5 commit be68366

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

556_ReshapeTheMatrix.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
func matrixReshape(_ nums: [[Int]], _ r: Int, _ c: Int) -> [[Int]] {
3+
let numbers = nums.reduce([], +)
4+
if numbers.count != r*c {
5+
return nums
6+
}
7+
8+
var reshaped = Array(repeating:[Int](), count:r)
9+
for count in 0..<numbers.count {
10+
reshaped[count/c].append(numbers[count])
11+
}
12+
return reshaped
13+
}
14+
}

0 commit comments

Comments
 (0)