Leetcode 898 Solution

This article provides solution to leetcode question 898 (transpose-matrix)

https://leetcode.com/problems/transpose-matrix

Solution

class Solution:
    def transpose(self, A: List[List[int]]) -> List[List[int]]:
        m = len(A)
        n = len(A[0])
        ans = [[0] * m for _ in range(n)]
        for i, j in itertools.product(range(m), range(n)):
            ans[j][i] = A[i][j]
        return ans