Class Solution

java.lang.Object
g0901_1000.s0965_univalued_binary_tree.Solution

public class Solution extends Object
965 - Univalued Binary Tree.<p>Easy</p> <p>A binary tree is <strong>uni-valued</strong> if every node in the tree has the same value.</p> <p>Given the <code>root</code> of a binary tree, return <code>true</code> <em>if the given tree is <strong>uni-valued</strong> , or</em> <code>false</code> <em>otherwise.</em></p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2018/12/28/unival_bst_1.png" alt="" /></p> <p><strong>Input:</strong> root = [1,1,1,1,1,null,1]</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2018/12/28/unival_bst_2.png" alt="" /></p> <p><strong>Input:</strong> root = [2,2,2,5,2]</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 100]</code>.</li> <li><code>0 <= Node.val < 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isUnivalTree

      public boolean isUnivalTree(TreeNode root)