867. Transpose Matrix

被 KO 的題目類型

LeetCode

Given a matrix A, return the transpose of A.

The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.

怎麼解

Matrix 題目都要先找 pattern 再解,所以這一題原本的 index 是以下

會變以下,然後重要的是找出 pattern

觀察 j 就是固定 row 的數字,而 i 都是 0, 1, 2

Last updated

Was this helpful?