问题

该文章的最新版本已迁移至个人博客【比特飞】,单击链接 https://www.byteflying.com/archives/3756 访问。

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

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

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

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

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

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

提示:

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


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.

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

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

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

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

Note:

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


示例

该文章的最新版本已迁移至个人博客【比特飞】,单击链接 https://www.byteflying.com/archives/3756 访问。

public class Program {public static void Main(string[] args) {int[][] nums = null;nums = new int[3][] {new int[] {1, 2, 3},new int[] {4, 5, 6},new int[] {7, 8, 9}};var res = Transpose(nums);ShowArray(res);Console.ReadKey();}private static void ShowArray(int[][] array) {foreach(var line in array) {foreach(var num in line) {Console.Write($"{num} ");}}Console.WriteLine();}private static int[][] Transpose(int[][] A) {var m = A.Length;var n = A[0].Length;var result = new int[n][];for(int i = 0; i < n; i++) {result[i] = new int[m];}for(var i = 0; i < n; i++) {for(var j = 0; j < m; j++) {result[i][j] = A[j][i];}}return result;}}

以上给出1种算法实现,以下是这个案例的输出结果:

该文章的最新版本已迁移至个人博客【比特飞】,单击链接 https://www.byteflying.com/archives/3756 访问。

1 4 7 2 5 8 3 6 9

分析:

显而易见,以上算法的时间复杂度为:  。

C#LeetCode刷题之#867-转置矩阵(Transpose Matrix)相关推荐

  1. LeetCode刷题(39)--Set Matrix Zeros

    如果矩阵的某一元素为0,则该行.该列都设为0,第一遍遍历设定需要设0的行列,需要特殊处理的是第0行和第0列,比如m[5][0]是0,则设定m[5][0]和m[0][0]为0,如果不加特殊出列,则m[0 ...

  2. C#LeetCode刷题-数组

    数组篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 43.1% 简单 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组 ...

  3. LeetCode 刷题之路(python版)

    摘自:https://blog.csdn.net/qq_32384313/article/details/90745354 LeetCode 刷题之路(python版) 小坏wz 2019-06-02 ...

  4. LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)

    LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...

  5. LeetCode刷题记录14——257. Binary Tree Paths(easy)

    LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...

  6. LeetCode刷题记录13——705. Design HashSet(easy)

    LeetCode刷题记录13--705. Design HashSet(easy) 目录 LeetCode刷题记录13--705. Design HashSet(easy) 前言 题目 语言 思路 源 ...

  7. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  8. LeetCode刷题记录11——290. Word Pattern(easy)

    LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...

  9. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

  10. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

最新文章

  1. dubbo学习过程、使用经验分享及实现原理简单介绍
  2. nio selector
  3. Oracle误删除数据的恢复方法
  4. linux检测hashicorp,在Ubuntu/CentOS/Debian上安装和配置Hashicorp Vault服务器的方法
  5. C++substr()用法
  6. 发布:NetBeans IDE 8.1 Beta
  7. 迁移学习训练集准确率一直上不去_可以提高你的图像识别模型准确率的7个技巧...
  8. 判断给定森林中有多少棵树特别版
  9. python3.7基础教程_关于本教程 |《Python 官方文档:入门教程 3.7.0》| Python 技术论坛...
  10. WEB编程学习之Windows安装运行Tomcat
  11. python copy函数用法_python shutil模块函数copyfile和copy的区别
  12. 爆料称小米平板5即将送网备案
  13. java文档注释 编写格式
  14. Magic Leap是快出产品的节奏,已开放内容开发者注册通道
  15. 网路是怎样连接的(十二)IP地址怎么看
  16. ios android混合开发框架,iOS基于Cordova框架的混合开发
  17. 老林学习笔记 :纯js 继承 闭包 与js实现继承原理 veu实现继承
  18. mysql中标识列是什么意思_数据库标识列是什么意思
  19. 微信小程序 一键保存视频到手机相册功能(视频来源为链接)
  20. 噩梦系列篇之Player随鼠标转向控制

热门文章

  1. 【jupyter notebook】低版本 python 安装jupyter及其问题解决
  2. 【今日CS 视觉论文速览】Mon, 14 Jan 2019
  3. Nginx学习之六-nginx核心进程模型
  4. 方法覆盖异常篇 java 1615387415
  5. 常用转义符的使用 java 0133
  6. mysql知识汇总2019
  7. django-模板的转义
  8. react中key的正确使用方式
  9. 解决Zend OPcache huge_code_pages: mmap(HUGETLB) fail
  10. 写给mybatis小白的入门指南