-
566. Reshape the Matrix코딩 테스트/Level 1 2022. 9. 7. 17:36반응형
https://leetcode.com/problems/reshape-the-matrix/
from typing import List class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: flat = tuple(each for row in mat for each in row) if len(flat) != r * c: return mat return [flat[i: i + c] for i in range(0, len(flat), c)]
class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: flat = tuple(each for row in mat for each in row) return mat if len(flat) != r * c else [flat[i: i + c] for i in range(0, len(flat), c)]
class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: return mat if len(flat := tuple(each for row in mat for each in row)) != r * c else [flat[i: i + c] for i in range(0, len(flat), c)]
반응형