/** * @param {number[][]} A * @return {number[][]} */ var transpose = function(A) { var row = A.length col = A[0].length new_col = [] for(let i=0;i<col;i++){ var new_row = [] for(let j=0;j<row;j++){ new_row.push(A[j][i]) } new_col.push(new_row) } return new_col };
嵌套循环生成新的二维数组。