【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 ...
随机推荐
- 自定义动画(仿Win10加载动画)
一.源代码 源代码及demo 二.背景 先看看Win10的加载动画(找了很久才找到): CPA推广甲爪广告联盟满30日结 [点击进入] 甲爪广告联盟,提供各类高单价CPA广告 单价高 收益好 日付广告 ...
- [算法练习]ZigZag Conversion
题目说明: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...
- js脚本快速评课----中科大教务系统
git地址:https://github.com/hzphzp/js_ustc_mis_teach 代码 for(var i = 1; i < document.getElementsByTag ...
- python字典的排序
# -*- coding:UTF-8 -*- def dict_sort(): # 按照value的值从大到小的顺序进行排序 dic = {'a': 31, 'bc': 5, 'c': 3, 'asd ...
- VS2013 添加 ILDasm
1.找到ILDasm.exe文件: 打开C:\Program Files\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools 2.vs外部工具添加 工 ...
- Jquery 获取Checkbox值,prop 和 attr 函数区别
总结: 版本 1.6 1.6 1.4 1.4 函数 勾选 取消勾选 勾选 取消勾选 attr('checked') checked undefined true false .prop('checke ...
- python源码学习(一)——python的总体架构
python源码学习(一)——python的总体架构 学习环境: 系统:ubuntu 12.04 STLpython版本:2.7既然要学习python的源码,首先我们要在电脑上安装python并且下载 ...
- D3——scale
d3.scale 比例尺 “Scales are functions that map from an input domain to an output range” Domains 定义域 和 R ...
- canvas小球 时间倒计时demo-优化
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- angularJs的工具方法3
一.angular.version 判断angular的版本 console.log(angular.version); 二.angular.equals 判断两 ...