Leetcode867.Transpose Matrix转置矩阵
给定一个矩阵 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 <= A.length <= 1000
- 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转置矩阵的更多相关文章
- [LeetCode] Transpose Matrix 转置矩阵
Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...
- Leetcode#867. Transpose Matrix(转置矩阵)
题目描述 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引. 示例 1: 输入:[[1,2,3],[4,5,6],[7,8,9]] 输出:[[1 ...
- 【LEETCODE】48、867. Transpose Matrix
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【Leetcode_easy】867. Transpose Matrix
problem 867. Transpose Matrix solution: class Solution { public: vector<vector<int>> tra ...
- 867. Transpose Matrix - LeetCode
Question 867. Transpose Matrix Solution 题目大意:矩阵的转置 思路:定义一个转置后的二维数组,遍历原数组,在赋值时行号列号互换即可 Java实现: public ...
- [Swift]LeetCode867. 转置矩阵 | Transpose Matrix
Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...
- LeetCode 867 Transpose Matrix 解题报告
题目要求 Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped ov ...
- C#LeetCode刷题之#867-转置矩阵(Transpose Matrix)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3756 访问. 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的 ...
- [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 ...
随机推荐
- Android开发 Camera2开发_1_拍照功能开发
介绍 google已经在Android5.1之后取消了对Camera1的更新,转而提供了功能更加强大的Camera2.虽然新版本依然可以使用Camera1但是,不管是各种机型适配还是拍照参数自定义都是 ...
- 微信小程序之组件的集合(六)
这个将是最后一篇关于小程序的记录了,课程接近尾声,最后一个是关于用户的page页面,看看这个页面中有哪些值得学习的地方! 一.page中my开发 这个主要是展示用户喜欢的杂志,以及用户的信息,需要创建 ...
- light oj 1079 01背包
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- gitlab merge request
分支提了mr之后, 又有commit 不用重新提mr,mr中会自动更新 要保证项目下的.git目录中有hooks这个目录(如果是从github迁移到gitlab的项目, 可能没有这个目录, 导致mr不 ...
- 原 ASP.net out 和ref之间的区别
ref和out都是C#中的关键字,所实现的功能也差不多,都是指定一个参数按照引用传递.对于编译后的程序而言,它们之间没有任何区别,也就是说它们只有语法区别.总结起来,他们有如下语法区别: 1.ref传 ...
- name和value的简单js用法
name和value: 例如: <input type="text" name="txt"/> name用于定义这个input收到的值的变量名,在上 ...
- InnoDB: Error number 24 means ‘Too many open files’
一.问题的描述 备份程序 执行前滚的时候报错.(-apply-log) InnoDB: Errornumber 24 means 'Too many open files'. InnoDB: Some ...
- Redis基本类型与常用命令
Redis基本类型一共有五类: 字符串类型(string): 散列类型(hash): 列表类型(list): 集合类型(sort): 有序集合类型(zset): 在redis中,所有的类型都是被以键值 ...
- 文件内容操作命令 cat、more、less、head、tail、wc、grep 命令详情
文件内容操作命令 cat.more.less.head.tail.wc.grep 命令详情 1) cat命令 用途:显示出文件的全部内容 格式:cat 目标文件 例: ...
- stringstream的使用 UVA 10815
水题题目描述就不写了 主要是发现stringstream真的是好用,可以把string绑定到stringstream中,然后就能以空格为分隔符分割出每个单词,听说每次重新创建stringstream开 ...