[easy]566. Reshape the Matrix
来源:互联网 发布:2017 a号黑豹数据 编辑:程序博客网 时间:2024/06/08 05:07
【原题链接】
题意:将数组转换为指定行数列数的数组。
用python刷leetcode真的是在作弊。不过人生苦短~
思路:将原数组转为一位数组,在利用分片截取list。
class Solution(object): def matrixReshape(self, nums, r, c): l = len(nums) * len(nums[0]) if l < r*c : return nums else : rs = [] rs2 = [] for li in nums: rs += li for i in range(0, r) : end = c*(i + 1) start = c*i rs2.append(rs[start:end:]) return rs2
阅读全文
0 0
- [easy]566. Reshape the Matrix
- 566. Reshape the Matrix Difficult : Easy
- LeetCode 566. Reshape the Matrix (Easy)
- 566. Reshape the Matrix
- 566.Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- hdu 2571 命运【java】【简单dp】
- warning: LF will be replaced by CRLF in tyrone-springboot-quickstart-withoutparent/pom.xml. The file
- 代码暂存
- CityEngine基础数据导入
- C++内存管理详解
- [easy]566. Reshape the Matrix
- [World Final 2017 E] Need For Speed (二分)
- 数据结构实验之图论六:村村通公路
- 部分和问题
- 面试热题——进制转换(n进制转换成2进制)
- 故障案例--mongo 3.0鉴权导致cpu居高不下
- nyoj 487点数(向量积判断三角形内部的整点)
- 如何查看codeblock的头文件
- HTML基础[思维导图]