1457. Pseudo-Palindromic Paths in a Binary Tree
Question
Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.
Return the number of pseudo-palindromic paths going from the root node to leaf nodes.
Solution
用数组bin[]记录一个树枝上的节点。
回溯,遇到根节点则判断数组bin[]中是否只有0个或1个奇数的数字。
Code
1 | /** |
1457. Pseudo-Palindromic Paths in a Binary Tree
https://xuanhe95.github.io/2022/09/14/1457-Pseudo-Palindromic-Paths-in-a-Binary-Tree/