博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【leetcode】867 - Transpose Matrix
阅读量:4487 次
发布时间:2019-06-08

本文共 714 字,大约阅读时间需要 2 分钟。

【题干描述】

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代码】

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

【所用python点】

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

 

转载于:https://www.cnblogs.com/Sinkinghost/p/9320564.html

你可能感兴趣的文章
【eclipse】启动不了报错java was started but returned exit code=13
查看>>
本地yum源 、阿里yum源、163yum源的配置安装
查看>>
codeforce 604B More Cowbell
查看>>
uvalive 3938 "Ray, Pass me the dishes!" 线段树 区间合并
查看>>
html中事件调用JavaScript函数时有return与没有return的区别
查看>>
[转帖]ASP.NET4中不要相信Request.Browser.Cookies,Form验证要用UseCookies
查看>>
Windows7中安装内存与可用内存不一致的解决办法
查看>>
HDU3065 AC自动机
查看>>
BUAA_OO_第一次作业总结
查看>>
数据结构-第10周作业(二叉树的创建和遍历算法)
查看>>
Java日志框架(二)
查看>>
[转载]SQL Server 2008 R2安装时选择的是windows身份验证,未选择混合身份验证的解决办法...
查看>>
[转]橘子版V880问题汇总及解决办法
查看>>
JS内置对象练习(慕课网题目)
查看>>
jQuery学习-事件之绑定事件(五)
查看>>
5个提高效率的编程工作环境
查看>>
使用SQL语句操作数据
查看>>
如何在Vue项目中使用vw实现移动端适配
查看>>
阻止默认行为-event.preventDefault();
查看>>
[FZYZOJ 1889] 厨房救济
查看>>