LeetCode 867 Transpose Matrix

LeetCode 867 Transpose Matrix Problem

Download Code
class Solution(object):
    def transpose(self, A):
        :type A: List[List[int]]
        :rtype: List[List[int]]
        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
        # Alternative Solution:
        # return zip(*A)

    # def transpose(self, A):
    #     res = []
    #     for i in range(len(A[0])):
    #         temp = []
    #         for j in range(len(A)):
    #             temp.append(A[j][i])
    #         res.append(temp)
    #     return res
Download Transpose Matrix.py

List of all Transpose Matrix problems

Leetcode 867 Transpose Matrix problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.