Given a matrix mat and two integers r and c, reshape mat into a matrix with r rows and c columns.
The elements of mat must be kept in the same row major order. If the reshape is not possible, return mat unchanged.
Note: Row major order means the matrix is read from left to right within each row, starting from the first row and moving to the last row.
Constraints:
m == mat.length
n == mat[i].length
1 <= m, n <= 100
-1000 <= mat[i][j] <= 1000
1 <= r, c <= 300
Given a matrix mat and two integers r and c, reshape mat into a matrix with r rows and c columns.
The elements of mat must be kept in the same row major order. If the reshape is not possible, return mat unchanged.
Note: Row major order means the matrix is read from left to right within each row, starting from the first row and moving to the last row.
Constraints:
m == mat.length
n == mat[i].length
1 <= m, n <= 100
-1000 <= mat[i][j] <= 1000
1 <= r, c <= 300