LeetCode75-1372-ZigZag
🧠 Summary of Thoughts
ZigZag = alternate walking left and right
- Use Depth-First Search (DFS) to traverse the tree recursively.
- Track the current path length separately for left and right directions.
- At each node:
- Update the maximum ZigZag length.
- Recurse to the left child with the path continuing from the right direction.
- Recurse to the right child with the path continuing from the left direction.
- Maintain a global or class-level variable to store the maximum path length found.
✅ Code(Java)
1 | |
LeetCode75-1372-ZigZag
https://powersixxx.github.io/leetcode-blog/2026/02/28/LeetCode75-1372-ZigZag/