g0901_1000.s0965_univalued_binary_tree.readme.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
965\. Univalued Binary Tree
Easy
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._
**Example 1:**
![](https://assets.leetcode.com/uploads/2018/12/28/unival_bst_1.png)
**Input:** root = [1,1,1,1,1,null,1]
**Output:** true
**Example 2:**
![](https://assets.leetcode.com/uploads/2018/12/28/unival_bst_2.png)
**Input:** root = [2,2,2,5,2]
**Output:** false
**Constraints:**
* The number of nodes in the tree is in the range `[1, 100]`.
* `0 <= Node.val < 100`