965 - 107 - 309。
965. 单值二叉树
// 12.14
// 12.17
class Solution {
bool checkValid(TreeNode* root, int prev) {
if(root == nullptr) return true;
if(root->val != prev) return false;
bool left = checkValid(root->left, prev);
bool right = checkValid(root->right, prev);
return left && right;
}
public:
bool isUnivalTree(TreeNode* root) {
if(root == nullptr) return true;
return checkValid(root, root->val);
}
};