867. Transpose Matrix Easy
1/**
2 * [867] Transpose Matrix
3 *
4 * Given a 2D integer array matrix, return the transpose of matrix.
5 * The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.
6 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/10/hint_transpose.png" style="width: 600px; height: 197px;" />
7 *
8 * Example 1:
9 *
10 * Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
11 * Output: [[1,4,7],[2,5,8],[3,6,9]]
12 *
13 * Example 2:
14 *
15 * Input: matrix = [[1,2,3],[4,5,6]]
16 * Output: [[1,4],[2,5],[3,6]]
17 *
18 *
19 * Constraints:
20 *
21 * m == matrix.length
22 * n == matrix[i].length
23 * 1 <= m, n <= 1000
24 * 1 <= m * n <= 10^5
25 * -10^9 <= matrix[i][j] <= 10^9
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/transpose-matrix/
31// discuss: https://leetcode.com/problems/transpose-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn transpose(matrix: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
37 vec![]
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_867() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.