A binary tree is uni-valued if every node in the tree has the same value.

Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise.

&nbsp;
Example 1:

Input: root = [1,1,1,1,1,null,1]
Output: true


Example 2:

Input: root = [2,2,2,5,2]
Output: false


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [1, 100].
	0 &lt;= Node.val &lt; 100


# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isUnivalTree(self, root: Optional[TreeNode]) -> bool:
        val1 = root.val
        self.tracker = False
        def dfs(root,val1):
            if not root:
                return 
            if root.val!=val1:
                self.tracker=True
            dfs(root.left,val1)
            dfs(root.right,val1)
            return 
        dfs(root,val1)
        
        if self.tracker == False:
            return True
        return False
class Solution {
    boolean ans=true;
    int firstVal=0;
    public boolean isUnivalTree(TreeNode root) {
        if(root==null)
          return ans; 
        firstVal=root.val;
        traversal(root);
      return ans;
    }
  private void traversal(TreeNode root)
  {
    if(root==null)
      return;
    if(root.val!=firstVal)
        ans=false;
    traversal(root.left);
    traversal(root.right);
  }
  
}
class Solution {
public:
    bool recur(TreeNode* root, int value){
        if(root==NULL)
            return true;
        if(root->val!=value){
            return false;
        }
        return recur(root->left,value) &&recur(root->right,value);

    }
    bool isUnivalTree(TreeNode* root) {
        if(root==NULL)
            return true;
        int value=root->val;
        return recur(root,value);

    }
};
var isUnivalTree = function(root) {
    if (!root) {
        return false;
    }

    const prev = root.val;
    const nodes = [root];

    for (const node of nodes) {
        if (node.val !== prev) {
            return false;
        }

        if (node.left) {
            nodes.push(node.left);
        }

        if (node.right) {
            nodes.push(node.right);
        }
    }

    return true;
};
    ```
Univalued Binary Tree