【leetcode】867 - Transpose Matrix
2024-08-27 12:00:43
【题干描述】
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]
最新文章
- 大家是怎么做Code Review的?
- jQuery validate 验证隐藏域
- atitit.web的动态include 跟变量传递 java .net php
- java web基础1Tomcat服务器基本知识
- css3常用动画效果集合01
- 十六、mysql 分区之 简单sql优化2
- GridView多行标题行、改造标题行、自定义标题行完美版
- Android 内核初识(4)属性服务器
- iOS两个强制旋转屏幕的方法
- HDU5058
- asp.net mvc 防止重复提交
- P1339 [USACO09OCT]热浪Heat Wave
- Activemq -- Spring 整合
- python和linux如何学习一门新的编程语言(python)(python基础结构)
- oracle的学习笔记(转)
- javamail模拟邮箱功能--邮件回复-中级实战篇【邮件回复方法】(javamail API电子邮件实例)
- ES6 三层for循环的链式写法
- SQL Server Mobile/Compact Edition 简单介绍
- Orchard运用 - 为评论启用Gravatar头像
- 大前端涉猎之前后端交互总结2:使用PHP进行表单数据上传与更新