/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public boolean isUnivalTree(TreeNode root) {
boolean flag=true;
if(root==null){
return true;
}
int t=root.val;
if(root.left!=null&&root.right!=null){
int rt=root.right.val;
int lt=root.left.val;
if(rt==lt&&rt==t){
return true&isUnivalTree(root.left)&isUnivalTree(root.right);
}
else{
return false;
}
}
else if(root.left==null&&root.right==null){
return true;
}
else if(root.left==null){
int rt=root.right.val;
if(rt==t){
return true&isUnivalTree(root.right);
}
else{
return false;
}
}
else{
int lt=root.left.val;
if(lt==t){
return true&isUnivalTree(root.left);
}
else{
return false;
}
}
}
}