Zero Rows and Columns
Imagine a table where a zero marks a failure, and that failure should clear the whole row and column. Write set_zeroes to return the modified matrix matrix. If a cell originally contains 0, every value in the same row and column must become 0. Apply the rule only from the original zeroes, not from zeroes created during the process.
Примеры
Ввод
[[1, 1, 1], [1, 0, 1], [1, 1, 1]]Вывод
[[1, 0, 1], [0, 0, 0], [1, 0, 1]]Ввод
[[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]]Вывод
[[0, 0, 0, 0], [0, 4, 5, 0], [0, 3, 1, 0]]Ввод
[[1, 2, 3]]Вывод
[[1, 2, 3]]Нужно реализовать
def set_zeroes(matrix: list[list[int]]) -> list[list[int]]:
Теги
arraymath
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónVisible tests
1
Input
[[1,1,1],[1,0,1],[1,1,1]]Expected
[[1,0,1],[0,0,0],[1,0,1]]2
Input
[[0,1,2,0],[3,4,5,2],[1,3,1,5]]Expected
[[0,0,0,0],[0,4,5,0],[0,3,1,0]]3
Input
[[1,2,3]]Expected
[[1,2,3]]4
Input
[[0]]Expected
[[0]]5
Input
[[1,0],[2,3]]Expected
[[0,0],[2,0]]6
Input
[[1,1,1],[1,0,1],[1,1,1],[1,1,1]]Expected
[[1,0,1],[0,0,0],[1,0,1],[1,0,1]]Focus radio
Paused · SomaFM · Fluid