给定一个矩阵 A, 返回 A 的转置矩阵。

矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。

示例 1:

输入:[[1,2,3],[4,5,6],[7,8,9]] 输出:[[1,4,7],[2,5,8],[3,6,9]]

示例 2:

输入:[[1,2,3],[4,5,6]] 输出:[[1,4],[2,5],[3,6]]

提示:

  1. 1 <= A.length <= 1000
  2. 1 <= A[0].length <= 1000
class Solution {
public:
vector<vector<int> > transpose(vector<vector<int> >& A) {
int r = A.size();
int c = A[0].size();
vector<vector<int> > res(c, vector<int>(r, 0));
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
res[j][i] = A[i][j];
}
}
return res;
}
};

Leetcode867.Transpose Matrix转置矩阵的更多相关文章

  1. [LeetCode] Transpose Matrix 转置矩阵

    Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...

  2. Leetcode#867. Transpose Matrix(转置矩阵)

    题目描述 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引. 示例 1: 输入:[[1,2,3],[4,5,6],[7,8,9]] 输出:[[1 ...

  3. 【LEETCODE】48、867. Transpose Matrix

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  4. 【Leetcode_easy】867. Transpose Matrix

    problem 867. Transpose Matrix solution: class Solution { public: vector<vector<int>> tra ...

  5. 867. Transpose Matrix - LeetCode

    Question 867. Transpose Matrix Solution 题目大意:矩阵的转置 思路:定义一个转置后的二维数组,遍历原数组,在赋值时行号列号互换即可 Java实现: public ...

  6. [Swift]LeetCode867. 转置矩阵 | Transpose Matrix

    Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...

  7. LeetCode 867 Transpose Matrix 解题报告

    题目要求 Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped ov ...

  8. C#LeetCode刷题之#867-转置矩阵(Transpose Matrix)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3756 访问. 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的 ...

  9. [LeetCode&Python] Problem 867. Transpose Matrix

    Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...

随机推荐

  1. 前缀数组O(n^3)做法

    前缀数组O(n^3)做法 s.substr()的应用非常方便 令string s = "; ); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = "56789&quo ...

  2. leetcode 376Wiggle Subsequence

    用dp解 1)up定义为nums[i-1] < nums[i] down nums[i-1] > nums[i] 两个dp数组, up[i],记录包含nums[i]且nums[i-1] & ...

  3. 装配SpringBean(六)--配置文件加载方式

    spring中的配置文件有两种: 以XML结尾的spring配置文件 以properties结尾的属性配置文件 在spring中有两种方式加载这两种文件: 通过注解+java配置的方式 通过XML的方 ...

  4. CCS开发指南

    第一章  CCS概述 1 1.1 CCS概述 1 1.2 代码生成工具 3 1.3 CCS集成开发环境 5 1.3.1 编辑源程序 5 1.3.2创建应用程序6 1.3.3 调试应用程序 6 1.4  ...

  5. JavaScript对象继承方式

    一.对象冒充 其原理如下:构造函数使用 this 关键字给所有属性和方法赋值(即采用类声明的构造函数方式).因为构造函数只是一个函数,所以可使 Parent 构造函数 成为 Children 的方法, ...

  6. CString转const char

    CString转换成const char      需要考虑一个因素: 你使用是否为unicode 不使用unicode: CString  Cstr("aaaaaaa"); co ...

  7. golang包引用

    一.我的GOPATH环境变量值如下图: 二.在GOPATH路径下面的的src目录下面的目录名称就是引用里面包的起始位置,如下图: 三.举例说明:这里引用同一个项目的包,源文件“learn/main/m ...

  8. 【html、CSS、javascript-13】前端框架Bootstrap

    1.Bootstrap前端框架:包含css样式.js插件.图标等 http://www.bootcss.com/ 2.Font Awesome:非常全的图标大全 https://fontawesome ...

  9. Django项目:CRM(客户关系管理系统)--29--21PerfectCRM实现King_admin查看页面美化

    {#table_data_list.html#} {## ————————08PerfectCRM实现King_admin显示注册表的字段表头————————#} {% extends 'king_m ...

  10. Git 对已经加入版本控制的文件,修改后希望不被提交办法

    参考网址:http://my.oschina.net/zlLeaf/blog/197740 问题举例:假设网站有一个数据库配置文件db.php,通过git做版本控制,已经将这个文件提交到git库中.但 ...