150 najlepszych wywiadówŁatwe

Ustaw zera macierzy

Szczegółowy przewodnik i implementacja Python dla problemu „Ustaw zera macierzy”.

Oświadczenie o problemie

Łatwe

Biorąc pod uwagę macierz macierzową z liczbami całkowitymi m x n, jeśli element ma wartość 0, ustaw cały jego wiersz i kolumnę na zera.

Musisz to zrobić na miejscu.

Zaimplementuj funkcję setZeroes(matrix: list) -> list, która modyfikuje macierz w miejscu i zwraca ją.

Ograniczenia
  • m == matrix.length
  • n == matrix[0].length
  • 1 <= m, n <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1

Przykłady

Example 1
Input
[[1,1,1],[1,0,1],[1,1,1]]
Output
[[1,0,1],[0,0,0],[1,0,1]]
Explanation

The element at position (1,1) is 0. So the entire row 1 and column 1 are set to 0.

Example 2
Input
[[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output
[[0,0,0,0],[0,4,5,0],[0,3,1,0]]
Explanation

Elements at (0,0) and (0,3) are 0. Row 0 becomes all zeros. Columns 0 and 3 become all zeros.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla matematyki i geometrii, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.