-
99. Transpose MatrixProblem Solving 2023. 1. 19. 17:58728x90
https://leetcode.com/problems/transpose-matrix/description/
Transpose Matrix - LeetCode
Transpose Matrix - Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices. [https://assets.leetcode.com/uploads/2021/02/10/hint_
leetcode.com
matrix를 transpose 하는 문제
class Solution: def transpose(self, matrix: List[List[int]]) -> List[List[int]]: new = [[] * len(matrix) for i in range(len(matrix[0]))] for idx, line in enumerate(matrix): for idx2, j in enumerate(line): new[idx2].append(j) return new
선형대수학 생각이 났다ㅎㅋ
원래는 swap 하는 방식으로 풀려고 했지만 그렇게 풀면 더 어렵다
'Problem Solving' 카테고리의 다른 글
100. Range Sum of BST (0) 2023.01.19 98. 수 뒤집기 (0) 2023.01.19 97. Remove Duplicates from Sorted Array (0) 2023.01.19 96. Remove Element (0) 2023.01.19 95. Sort Array By Parity II (0) 2023.01.19