Untitled
unknown
plain_text
a year ago
574 B
2
Indexable
Never
int value(TreeNode<int>* root){ if(root==NULL) return 0; int x=value(root->left); int y=value(root->right); return root->val+x+y; //return entire value of node } bool cec(TreeNode<int>* root){ if(root==NULL) return true; if(root->left==NULL && root->right==NULL) return true; //check for leaf if(!cec(root->left)) return false; if(!cec(root->right)) return false; if((value(root->left)+value(root->right))!=root->val) return false; return true; } bool isSumTree(TreeNode<int>* root) { return cec(root); }