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

本文共 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

你可能感兴趣的文章
字符串之strcmp
查看>>
最长公共子序列(不连续)
查看>>
微服务:Java EE的拯救者还是掘墓人?
查看>>
如何在Centos里面,把.net core程序设为开机自启动
查看>>
1920*1080pc端适配
查看>>
Nutch系列1:简介
查看>>
前端UI框架选择区别对比推荐
查看>>
栈 队列 和 双向队列
查看>>
从垃圾回收看闭包
查看>>
Intel Core Microarchitecture Pipeline
查看>>
如何去除交叉表的子行(列)的小计?
查看>>
Web字体(链接)嵌入
查看>>
switch… case 语句的用法
查看>>
day07补充-数据类型总结及拷贝
查看>>
语言、数据和运算符
查看>>
正则表达式30分钟入门教程
查看>>
sqlserver try catch·
查看>>
怎么在三维世界里叙述五维故事
查看>>
1028: 可乐(2018年中南大学研究生复试机试题 )
查看>>
珍藏的最全的windows操作系统快捷键
查看>>