You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0800-0899/0867.Transpose Matrix/README_EN.md
+30-6
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,15 @@ tags:
56
56
57
57
<!-- solution:start -->
58
58
59
-
### Solution 1
59
+
### Solution 1: Simulation
60
+
61
+
Let $m$ be the number of rows and $n$ be the number of columns in the matrix $\textit{matrix}$. According to the definition of transpose, the transposed matrix $\textit{ans}$ will have $n$ rows and $m$ columns.
62
+
63
+
For any position $(i, j)$ in $\textit{ans}$, it corresponds to the position $(j, i)$ in the matrix $\textit{matrix}$. Therefore, we traverse each element in the matrix $\textit{matrix}$ and transpose it to the corresponding position in $\textit{ans}$.
64
+
65
+
After the traversal, we return $\textit{ans}$.
66
+
67
+
The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows and columns in the matrix $\textit{matrix}$, respectively. Ignoring the space consumption of the answer, the space complexity is $O(1)$.
0 commit comments