Transpose Matrix - Leetcode 867 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
3:57 - Coding Explanation

leetcode 867

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

There's also a nice Pythonic one liner to transpose any matrix: list(zip(*matrix))

kartheyansivalingam
Автор

Also you could do inner list comprehension:

class Solution:
def transpose(self, matrix: List[List[int]]) -> List[List[int]]:
return [
[row[i] for row in matrix]
for i in range(len(matrix[0]))
]

SurenKhorenyan
Автор

One loop solution
rows = len(matrix)
cols = len(matrix[0])

returnM = []
for i in range(cols):
row = []
for j in range(rows):
row.append(matrix[j][i])
returnM.append(row)
return returnM

dusvn
Автор

Can you do an explanation of LC 310 pls

CS_nb
Автор

I was asked this question in second year of my uni and I was among the only 3 people who solved it that time .... seeing it in Easy section makes me wonder how bad are my uni students....

AbhishekMakwana-pv
visit shbcf.ru