1class Solution {2private:3void dfs(TreeNode *root, int &ans, unordered_map<int, int> &m) {4if (!root) return;5m[root->val]++;67if (!root->left and !root->right) {8int oddCnt = 0;9for (auto it : m) {10if (it.second % 2 != 0) oddCnt++;11}12if (oddCnt <= 1) ans++;13}1415dfs(root->left, ans, m);16dfs(root->right, ans, m);1718m[root->val]--;19}2021public:22int pseudoPalindromicPaths(TreeNode *root) {23if (root == NULL) return 0;2425int ans = 0;2627unordered_map<int, int> m;2829dfs(root, ans, m);3031return ans;32}33};