【题干描述】

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. Spring Data MongoDB 基础查询

    有两种方式查询 BasicQuery 和 Query 一.BasicQuery BasicQuery query = new BasicQuery("{ age : { $lt : 26 } ...

  2. Maven-pom-configuration

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  3. Visual Studio解决方案vs2005/vs2008/vs2010/vs2012/vs2013/vs2015版本互相转换工具

    原文:http://blog.csdn.net/xiejiashu/article/details/52397641   本文转自EasyDarwin团队成员Alex的博客:http://blog.c ...

  4. 面向对象进阶------>内置函数 str repr new call 方法

    __new__方法: 我们来讲个非常非常重要的内置函数和init一样重要__new__其实在实例话对象的开始  是先继承父类中的new方法再执行init的  就好比你生孩子 先要把孩子生出来才能对孩子 ...

  5. 卸载Sharepoint2016后。重新安装提示 系统从以前的安装重新启动,或更新正在等待错误

    卸载Sharepoint2016 重启N遍,不停地重启.需要删除注册表项 下的 .将PendingFileRenameOperations键项删除,再重新安装就可以安装成功.

  6. MVC过滤器的使用总结

    一.过滤器的作用 在MVC项目当中,当我们要实现这些功能时:身份验证,异常处理.日志记录,性能统计,如果按照一般的做法那就需要在每个页面重复做这些工作,这样做起来不仅费时费力,代码也会变得冗余难懂,如 ...

  7. [BZOJ 1592] Making The Grade路面修整

    1592: [Usaco2008 Feb]Making the Grade 路面修整 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 704  Solv ...

  8. BZOJ 1001 狼抓兔子 平面图的最小割

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1001 题目大意: 见链接 思路: 求最小割,平面图的最小割等价于对偶图的最短路 直接建 ...

  9. [WebKit] JavaScriptCore解析--基础篇 (一)JSC与WebCore

    先看一下官方的基本介绍,短短几句就塞满了关键字. SquirrelFish,正式名称是JavaScriptCore,包括register-based(基于寄存器的虚拟机), direct-thread ...

  10. 关于使用Filter降低Lucene tf idf打分计算的调研

    将query改成filter,lucene中有个QueryWrapperFilter性能比较差,所以基本上都须要自己写filter.包含TermFilter,ExactPhraseFilter,Con ...