【leetcode】867 - Transpose Matrix
【题干描述】
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的更多相关文章
- 【LeetCode】867. Transpose Matrix 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 先构建数组再遍历实现翻转 日期 题目地址:https ...
- 【Leetcode_easy】867. Transpose Matrix
problem 867. Transpose Matrix solution: class Solution { public: vector<vector<int>> tra ...
- 【LeetCode】-- 73. Set Matrix Zeroes
问题描述:将二维数组中值为0的元素,所在行或者列全set为0:https://leetcode.com/problems/set-matrix-zeroes/ 问题分析:题中要求用 constant ...
- 【LeetCode】766. Toeplitz Matrix 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:两两比较 方法二:切片相等 方法三:判断每条 ...
- 【LeetCode】73. Set Matrix Zeroes 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 原地操作 新建数组 队列 日期 题目地址:https ...
- 【LeetCode】59. Spiral Matrix II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 维护四个边界和运动方向 保存已经走过的位置 日期 题 ...
- 【LeetCode】54. Spiral Matrix 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 维护四个边界和运动方向 保存已经走过的位置 日期 题 ...
- 【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 ...
- 【leetcode】59.Spiral Matrix II
Leetcode59 Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 ...
随机推荐
- 使用js在HTML中自定义字符串格式化方法
Python中支持字符串格式化,其基本形式如下: str = "I'm {name},{age} years old" print(str.format(name="te ...
- MathQuill.js
MathQuill.js通过html.css.javascript实现数学公式 <p>Type math here: <span id="math-field"& ...
- thinkPHP -01- thinkPHP5.0 安装与测试
thinkPHP -01- thinkPHP5.0 安装与测试 1.thinkPHP 5 官网下载地址:http://www.thinkphp.cn/down.html 2.打开 Wampserver ...
- 中国国内 - 可用API合集
中国国内 - 可用API合集 收录一篇中国国内可用API合集,分享给大家 目录 笔记 出行 词典 电商 地图 电影 即时通讯 开发者网站 快递查询 旅游 社交 视频 天气 团队协作 图片与图像处理 外 ...
- MUI框架-07-HBuilder+夜神安卓模拟器
MUI框架-07-HBuilder+夜神安卓模拟器 有时候我们在 HBuilder 里面 web 浏览器预览我们的 MUI 项目界面时,总感觉这个 web 浏览器随便拖拉比例,大小可调,但它毕竟是浏览 ...
- Java和C# RSA加解密相互通信和使用公钥加密传输
关于JAVA和C#加解密通讯的话,可以用这个BouncyCastle插件,会帮助你解决很多问题 http://www.bouncycastle.org/ //c#使用java给的公钥进行rsa加密 p ...
- firewall 如何开放端口
转自官方网页:http://www.firewalld.org/documentation/howto/open-a-port-or-service.html How to open port 80/ ...
- Windows 7 控制面板Update选项灰色解决办法
具体解决方法是开始-运行-regedit,打开注册表编辑器,在注册表里找: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows,展开Windo ...
- C#网络编程(二)应用篇
(一)TcpListen类.TcpClient类 TcpListener类和TcpClient类都是System.Net.Sockets命名空间下的类,利用TcpListener和TcpClient可 ...
- 提升PHP速度
PHP的优点之一是速度很快,对于一般的网站应用,可以说是已经足够了.不过如果站点的访问量很高.带宽窄或者其它的因素令服务器产生性能瓶颈的时候,你可能得想想其它的办法来进一步提高PHP的速度了.这篇文章 ...