250. Count Univalue Subtrees

Practice Count Univalue Subtrees for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

A uni-value subtree is a subtree (a node together with all of its descendants) in which every node has the same value. Given the root of a binary tree, return the number of uni-value subtrees.

Example

root = [5,1,5,5,5,null,5]  ->  4
root = []                  ->  0
root = [5,5,5,5,5,null,5]  ->  6

Constraints