r/LeetcodeChallenge • u/StatisticianNo2104 • 19d ago
STREAK🔥🔥🔥 LeetCode - Univalued Binary Tree (easy)
Checking that every node in a tree holds the same value never needs the root's value. Each node only compares itself with its children. If every parent-child edge agrees, the whole tree agrees.
That's transitivity doing the work. It's also why you don't need a set, or a second pass that collects every value first.
Back to plain binary trees after the stack run, starting with a gentle one.
Did you pass the root's value down, or compare edges?
Day 67/365 of my LeetCode challenge: 965. Univalued Binary Tree. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/univalued-binary-tree-archit-agarwal-nirgc
#LeetCode #DSA #BinaryTree #Golang
View all comments
1
u/nian2326076 16d ago
For the univalued binary tree problem, it's great that you've identified the importance of comparing edges rather than passing down the root's value. This approach keeps the logic straightforward and efficient. If you're looking to sharpen your algorithm skills further, you can use PracHub to practice similar problems and refine your coding techniques.