Skip to content

#1372 - Longest ZigZag Path in a Binary Tree

MediumBinary Tree - DFS
Open on LeetCode

A ZigZag path starts at any node and alternates between going left and right (or right and left). The length is the number of edges traversed. Return the longest ZigZag path in the tree.

InputOutput
root = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1]3
root = [1,1,1,null,1,null,null,1,1,null,1]4
root = [1]0

Released under the MIT License.