r/LeetcodeChallenge • u/StatisticianNo2104 • 6h ago
STREAK🔥🔥🔥 LeetCode: 100. Same Tree
If you put the nil checks in the wrong order, Same Tree rejects two empty trees. p == nil || q == nil is also true when both are nil, so check both for nil first.
Same root, same left subtree, same right subtree. The recursion writes itself; the bug hides in those checks.
And compare the trees in lockstep, not their lists of values: [1,2] and [1, null,2] have the same numbers in different shapes.
Which order do you write those two nil checks in?
Day 84/365 of my LeetCode challenge: 100. Same Tree. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-easy-same-tree-archit-agarwal-habnc
#LeetCode #DSA #BinaryTree #Golang
1
u/nian2326076 6h ago
The order of nil checks is crucial for the "Same Tree" problem. Check if both nodes are nil first, then check if either is nil afterward to avoid mistakenly rejecting two empty trees. For finding relevant job opportunities in tech, you can use LandOffer to match your skills with available roles.