867. 转置矩阵

 

 

 

 

 1 class Solution(object):
 2     def transpose(self, A):
 3         """
 4         :type A: List[List[int]]
 5         :rtype: List[List[int]]
 6         """
 7         hang = len(A)
 8         lie = len(A[0])
 9         ans = []
10         for i in range(lie):
11             temp = []
12             for j in range(hang):
13                 temp.append(A[j][i])
14             ans.append(temp)
15         return ans
16 
17 
18 if __name__ == '__main__':
19     solution = Solution()
20     print(solution.transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))

 

posted @ 2020-04-29 09:51  人间烟火地三鲜  阅读(147)  评论(0编辑  收藏  举报