fbaquant / LeetCode

1 stars 0 forks source link

Transpose Matrix #104

Open juneharold opened 3 months ago

juneharold commented 3 months ago

Simply copying A[i][j] to AT[j][i] works.

class Solution(object):
    def transpose(self, A):
        R, C = len(A), len(A[0])
        ans = [[None] * R for _ in xrange(C)]
        for r, row in enumerate(A):
            for c, val in enumerate(row):
                ans[c][r] = val
        return ans