Ctrl K

One-Value Tree

Easy
You get the root of a binary tree. Return True if every node of the tree holds the same number, and False otherwise.
Example 1
root=tree_node([4, 4, 4, None, 4]) → True

All four nodes hold 4.

Example 2
root=tree_node([3, 3, 3, 3, 8]) → False

One leaf holds 8 while the rest hold 3.

Constraints
  • The tree has between 1 and 100 nodes
  • 0 ≤ Node.val < 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsIdentical Trees EasyMirror-Image Tree EasyTree Height EasyNearest Leaf Depth EasyLeaf Path With a Given Total Easy
loading Python…
Input
root=tree_node([4, 4, 4, None, 4])
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.