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 ...
随机推荐
- Spring Boot 集成Jsp与生产环境部署
一.简介 提起Java不得不说的一个开发场景就是Web开发,也是Java最热门的开发场景之一,说到Web开发绕不开的一个技术就是JSP,因为目前市面上仍有很多的公司在使用JSP,所以本文就来介绍一下S ...
- C动态分配内存
malloc分配内存时不初始化,calloc分配内存并进行初始化.
- vue.js_07_vue-resource的请求方式
1.vue-resource 实现 get, post, jsonp请求 <body> <div id="app"> <input type=&quo ...
- javascript基础:语法与html结合方式
一.基本语法: 1.与html结合方式 1.内部JS: * 定义<script>,标签体内容就是JS代码 2.外部JS: * 定义<script>,通过src属性引入外部的 ...
- Redis源码解析:22sentinel(三)客观下线以及故障转移之选举领导节点
八:判断实例是否客观下线 当前哨兵一旦监测到某个主节点实例主观下线之后,就会向其他哨兵发送"is-master-down-by-addr"命令,询问其他哨兵是否也认为该主节点主观下 ...
- JAVA面试常见问题之数据库篇
1.MySQL 索引使用的注意事项 更新频繁的列不要加索引 数据量小的表不要加索引 重复数据多的字段不要加索引,比如性别字段 首先应该考虑对where 和 order by 涉及的列上建立索引 2.D ...
- php连接数据库查询方法(还少一种pdo方法)
<?php header("content-type:text/html;charset=utf-8"); $conn = mysql_connect("local ...
- 严格模式下顶层箭头函数this指向的是全局对象
我们知道普通函数调用,this在非严格模式下指向全局对象,在严格模式下是undefined.那箭头函数呢?我们知道,箭头函数没有自己的this,它的this是最近外层非箭头函数的this,那直接在顶层 ...
- 关于网上大量对Vue双向绑定的错误理解
对于Vue的双向绑定,现在基本是个前端都听说过,面试官也喜欢问这个问题.但对于Vue双向绑定的原理,掘金.博客园和segmentfault等技术社区充斥着大量的错误文章.这些文章的题目基本样子如下 “ ...
- java如何使用 tesseract 4.0.0-1.4.4
提示: 建议直接使用tess4j,tess4j是对tesseract的封装,使用更简单 首先引入依赖 <!-- https://mvnrepository.com/artifact/org.by ...