bool helper(TreeNode* root, int& count){

```
if(root == NULL) return true;
bool leftRet = helper(root->left,count);
bool rightRet = helper(root->right,count);
bool retV = false;
if (leftRet && rightRet){
if ((root->left == NULL || root->left->val == root->val) && (root->right == NULL || root->right->val == root->val)){
count++;
retV = true;
}
}
return retV;
}
int countUnivalSubtrees(TreeNode* root) {
if(root == NULL) return 0;
int count = 0;
bool res = helper(root, count);
return count;
}
```