#867
Transpose Matrix
newbie · 225 · lc easy +17 · verified · 76% accepted · 4,174 likes · top 87%
Description
Given a 2D integer array matrix, return its transpose.
The transpose of a matrix is obtained by reflecting it along its main diagonal, swapping its row and column indices.
Example 1:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[1,4,7],[2,5,8],[3,6,9]]
Example 2:
Input: matrix = [[1,2,3],[4,5,6]]
Output: [[1,4],[2,5],[3,6]]
Code
1
2
3