filmov
tv
LeetCode 867: Transpose Matrix ✅ Easy solution ✅

Показать описание
LeetCode 867 Transpose Matrix
To obtain the transpose, we created a new matrix called result with dimensions (m * n), where m represents the number of columns in the original matrix and n represents the number of rows. We then iterated through the elements of the input matrix using nested loops. The outer loop iterated over the rows, and the inner loop iterated over the columns. For each element at position (row, col) in the input matrix, we assigned its value to the corresponding position (col, row) in the result matrix. Finally, we returned the result matrix as the transpose of the input matrix.
To obtain the transpose, we created a new matrix called result with dimensions (m * n), where m represents the number of columns in the original matrix and n represents the number of rows. We then iterated through the elements of the input matrix using nested loops. The outer loop iterated over the rows, and the inner loop iterated over the columns. For each element at position (row, col) in the input matrix, we assigned its value to the corresponding position (col, row) in the result matrix. Finally, we returned the result matrix as the transpose of the input matrix.