Reshape the Matrix1 [Leetcode][자바스크립트][Easy] 566. Reshape the Matrix 풀이1 /** * 566_ReshapeTheMatrix.js * Easy * https://leetcode.com/problems/reshape-the-matrix/ */ var matrixReshape = function(mat, r, c) { if (mat[0].length * mat.length !== r * c) return mat; let temp = []; mat.forEach((subArr) => temp = temp.concat(subArr)); const answer = [[]]; temp.forEach((val) => { if (answer[answer.length - 1].length === c) answer.push([]); answer[answer.length - 1].push(v.. 2022. 1. 9. 이전 1 다음