【题干描述】

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.(一矩阵A,返回其转置)

【思路】

  • 直接处理,A[i][j]的值赋值给output[j][i].

【python代码】

 input = [[1, 2, 3], [4, 5, 6]]
row = len(input)
col = len(input[0]) output = [[None]*row for _ in range(col)] for j in range(col):
for i in range(row):
output[j][i] = input[i][j]
print output

【所用python点】

  • range()和xrange()的区别:https://www.cnblogs.com/Sinkinghost/p/9320070.html
  • [[None]*row for _ in range(col)] 的 “_” 其实可以用 任意变量替换。
  • [None]*row 的结果是[None, None, None]

【leetcode】867 - Transpose Matrix的更多相关文章

  1. 【LeetCode】867. Transpose Matrix 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 先构建数组再遍历实现翻转 日期 题目地址:https ...

  2. 【Leetcode_easy】867. Transpose Matrix

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

  3. 【LeetCode】-- 73. Set Matrix Zeroes

    问题描述:将二维数组中值为0的元素,所在行或者列全set为0:https://leetcode.com/problems/set-matrix-zeroes/ 问题分析:题中要求用 constant ...

  4. 【LeetCode】766. Toeplitz Matrix 解题报告

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:两两比较 方法二:切片相等 方法三:判断每条 ...

  5. 【LeetCode】73. Set Matrix Zeroes 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 原地操作 新建数组 队列 日期 题目地址:https ...

  6. 【LeetCode】59. Spiral Matrix II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 维护四个边界和运动方向 保存已经走过的位置 日期 题 ...

  7. 【LeetCode】54. Spiral Matrix 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 维护四个边界和运动方向 保存已经走过的位置 日期 题 ...

  8. 【LeetCode】73. Set Matrix Zeroes

    题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Fo ...

  9. 【leetcode】59.Spiral Matrix II

    Leetcode59 Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 ...

随机推荐

  1. 文件路径太长无法删除 robocopy

    方法一:新建空文件夹 D:\temp robocopy D:\temp D:\target\source\test  /purge 或者在同一目录下,建一个空文件夹, test 在cmd下切换进入到当 ...

  2. Architecture And Framework

    高屋建瓴 From Up to Down. Outside into inside. Interface-Oriented Framework with dynamic configuration. ...

  3. Python power spectral 功率谱

    You can also use scipy.signal.welch to estimate the power spectral density using Welch’s method. Her ...

  4. Python with VS Code

    1. 基本的代码结构为: 2.

  5. 如何从只会 C++ 语法的水平到达完成项目编写软件的水平?

    原文:https://www.zhihu.com/question/29702729 学习 C++ 有一段时间了,但只是停留在熟悉语法阶段,在看 C++primer,不过感觉这本书比较深奥,不太适合, ...

  6. PyCharm2018 安装及破解方法

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u012278016/article/details/81738676 目录 1>. 安装 2& ...

  7. Word操作总结

    1.竖向选择 Notepad中:先把鼠标光标放在起始位置,然后同时按 Alt+Ctrl 或Alt+shift键,然后移动鼠标选取内容. Word中只能用Alt+Shift .

  8. 将eChart图片利用POI导出到Excel

    在使用POI进行将数据导出到Excel时, 若要将eChart在前端生成的统计图(如柱状图.折线图.饼图等)一并导出,使用POI在后台构建数据图比较复杂,因此我选择将eChart在前端的统计图的bas ...

  9. Scratch www 系统搭建

    原文地址:https://blog.csdn.net/litianquan/article/details/82735809 Scratch www要基于Nodejs的环境才可以运行,我尝试了在Win ...

  10. 企业级Apache详解

    安装Apache #Apache安装 rpm -qa|grep httpd yum install httpd #2编译安装: -->推荐安装 cd /root/software yum -y ...