Sekcja DSAŚredni

Drzewo symetryczne

Szczegółowy przewodnik i implementacja Python dla problemu „Drzewo symetryczne”.

Oświadczenie o problemie

Średni

Napisz funkcję is_symmetric(tree_arr), która pobiera tablicową reprezentację drzewa binarnego tree_arr i sprawdza, czy drzewo jest symetryczne (odbicie samego siebie wokół środka, pasujące zarówno do struktury, jak i wartości).

Ograniczenia
  • 0 <= len(tree_arr) <= 1000

Przykłady

Example 1
Input
tree_arr = [1, 2, 2, 3, 4, 4, 3]
Output
True
Explanation

The tree is symmetric in both shape and node values.

Example 2
Input
tree_arr = [1, 2, 2, None, 3, None, 3]
Output
False
Explanation

Left child 2 has right child 3, right child 2 has right child 3. Values match but structures are not mirrors.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla drzew, 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.