store as pair number in stack with corresponding node, shown as bit
ex: {2,0} {3,4} {1,4} {3,12} {1,12} {1,6}
for {2,0}: since 2 is root, we give it path=0
for other branch like {3,4}: we give it path= parent-path ^ (1<<parent-value), that is,
for leaf nodes like {3,12}
we give it path= parent-path ^ (1<<parent-value)
and check if path&(path-1)==0
Step
keep a stack to traverse the tree using DFS
store current-path ^ current->value to children node and put these children to stack every time
if arrive the leaf(no left and right child), we check if the path&(path-1)==0,
we want to check if there's only one set when the number represented in bit form
ex: 0100 will be accepted because
ex: 1111 will be rejected because
Why keep current-path ^ current->value as frequency count?
Take 2-3-3 this path for example
appear even time: after Xor operation, digit=0
appear odd time: after Xor operation, digit=1
Since only when there's at most one element has odd frequency in a list can form a palindrome, we keep the count of element in the path. Then check the count when we arrived leaf