JAVA_Reshape the Matrix_LeetCode 566


JAVA_Reshape the Matrix_LeetCode 566

JAVA_Reshape the Matrix_LeetCode 566 풀이 class Solution { public int[][] matrixReshape(int[][] mat, int r, int c) { int n = mat[0].length; if(r * c != mat.length * n) { return mat; } int[][] ans = new int[r][c]; for(int i = 0; i < r * c; i++) { ans[i/c][i%c] = mat[i/n][i%n]; } return ans; } } * 출처 Reshape the Matrix - LeetCode Reshape the Matrix - In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original d...


#JAVA #JAVA_LeetCode566 #JAVA_ReshapetheMatrix #JAVA_ReshapetheMatrix_LeetCode566 #ReshapetheMatrix_LeetCode566

원문링크 : JAVA_Reshape the Matrix_LeetCode 566