LeetCode 1372 - Longest ZigZag Path in a Binary Tree - Python

preview_player
Показать описание
Notes:
- I forgot the int type hint for cur_len. This is only for readability though

- Why is the base case for null nodes? The zigzag path must end at a null node because if the node before the null one DID have a child in the null's position then it would extended by 1. This repeats until we eventually have to reach a null node.

0:00 Reading the problem
1:27 Solution and diagram
2:50 Coding
Рекомендации по теме
join shbcf.ru