| https://leetcode.com/problems/reshape-the-matrix/ | Easy |
|---|
class Solution {
fun matrixReshape(mat: Array<IntArray>, r: Int, c: Int): Array<IntArray> {
val m = mat.size
val n = mat[0].size
if (m * n != r * c) return mat
val result = Array(r) { IntArray(c) }
for (i in 0 until m * n) {
result[i / c][i % c] = mat[i / n][i % n]
}
return result
}
}