566. Reshape the Matrix
来源:互联网 发布:淘宝微能量运动旗舰店 编辑:程序博客网 时间:2024/06/04 17:44
class Solution(object): def matrixReshape(self, nums, r, c): """ :type nums: List[List[int]] :type r: int :type c: int :rtype: List[List[int]] """ res=[[None]*c for i in range(r)] if len(nums)*len(nums[0]) != r*c: return nums else: for i in range(len(nums)*len(nums[0])): res[i/c][i%c] = nums[i/len(nums[0])][i%len(nums[0])] return res
- 关于二维列表的初始化
res=[[None]*c for i in range(r)]
,c是列数,i是行数,这里的i无实际意义,res=[[None]*c for _ in range(r)]
0 0
- 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
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- 566. Reshape the Matrix
- JFinal
- 旋转矩阵与四元数
- 实现三个并排div,两边固定宽度,中间自适应的四个方法
- tcpdump命令
- hibernate的方法运用
- 566. Reshape the Matrix
- dubbo Filter源码分析
- VGA、DVI、HDMI哪个好?三种视频信号接口有什么区别?
- Linux Shell 之 Shell中的函数调用
- 确定比赛名次 (拓扑排序)
- uses-sdk tools:overrideLibrary uses-sdk:minSdkVersion 1 cannot be smaller than version 9
- 深入分析 ThreadLocal 内存泄漏问题
- JAVA利用FreeMarker生成(导出)Word文档
- Nginx反向代理的简单配置应用