[leetcode] 867. Transpose Matrix

网友投稿 746 2022-10-01

[leetcode] 867. Transpose Matrix

[leetcode] 867. Transpose Matrix

Description

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.

Example 1:

Input:

[[1,2,3],[4,5,6],[7,8,9]]

Output:

[[1,4,7],[2,5,8],[3,6,9]]

Example 2:

Input:

[[1,2,3],[4,5,6]]

Output:

[[1,4],[2,5],[3,6]]

Note:

1 <= A.length <= 10001 <= A[0].length <= 1000

分析

题目的意思是:给定一个矩阵,转置矩阵。

注意m和n是不相等的这种情况,所以我们在做题的时候,要注意用res数组的大小要对应。

代码

class Solution {public: vector> transpose(vector>& A) { int m=A.size(); int n=A[0].size(); vector> res(n,vector(m,0)); for(int i=0;i

参考文献

​​Approach 1: Copy Directly​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信小程序网络超时怎么办?(加载小程序超时怎么办)
下一篇:[leetcode] 669. Trim a Binary Search Tree
相关文章

 发表评论

暂时没有评论,来抢沙发吧~