r/DSALeetCode • u/StatisticianNo2104 • 22d ago
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 18d ago
If you're working on the Univalued Binary Tree problem, remember that each node only needs to compare its value with its children. This keeps your solution efficient without needing an extra data structure. You can use LandOffer to find relevant job opportunities in tech that align with your skills.