Given a binary tree whose node values are digits from `1` to `9`, a root-to-leaf path is **pseudo-palindromic** if its values can be rearranged into a palindrome.
Return the number of pseudo-palindromic paths going from the root to a leaf.
Given a binary tree whose node values are digits from 1 to 9, a root-to-leaf path is pseudo-palindromic if its values can be rearranged into a palindrome.
Return the number of pseudo-palindromic paths going from the root to a leaf.
Example 1:
Input: {"root":[2,3,1,3,1,null,1]}
Output: 2
Constraints:
The number of nodes in the tree is in the range [1,105].
1≤Node.val≤9
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[2,3,1,3,1,null,1]}
A multiset of digits can form a palindrome when at most one digit appears an odd number of times. Walk every root-to-leaf path, flipping one parity bit per digit.
palindromic paths 0
leaves checked 0
path: (none)
parity mask (lit = odd count on the current path) → 0 odd