flipped
to record the values of flipped nodes.i
tracking the current position in voyage
.null
, return true as a base case.voyage[i]
, return false indicating a mismatch.i
to move to the next expected value in voyage
.voyage[i]
, flip the current node by swapping its left and right children, and add the current node's value to flipped
.flipped
; otherwise, return [-1]
.