数据结构基础教程,第四天内容有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计380个文字,预计阅读时间需要2分钟。
pythonclass Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: m, n=len(mat), len(mat[0]) if m * n !=r * c: return mat
result=[[0] * c for _ in range(r)] for i in range(m * n): result[i // c][i % c]=mat[i // n][i % n]
return result
566. 重塑矩阵
给定一个mxn的数组,重构为rxc的数组。
本文共计380个文字,预计阅读时间需要2分钟。
pythonclass Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: m, n=len(mat), len(mat[0]) if m * n !=r * c: return mat
result=[[0] * c for _ in range(r)] for i in range(m * n): result[i // c][i % c]=mat[i // n][i % n]
return result
566. 重塑矩阵
给定一个mxn的数组,重构为rxc的数组。

