All problems
Same Tree Check
Problem
Check whether two binary trees given in level order are identical.
a and b are LeetCode-style level-order lists where None marks a missing node. Compare the normalized level-order sequences after trimming trailing None placeholders.
Return True when the trees have the same shape and values, otherwise False.
Hint
Trailing None placeholders do not change a tree, but Nones in the middle do.
Test cases
case 1
in: [[1,2,3],[1,2,3]]
expected: true
case 2
in: [[1,2],[1,null,2]]
expected: false
case 3
in: [[],[]]
expected: true
case 4
in: [[1,2,3],[1,2,4]]
expected: false
case 5
in: [[1,2,null,3],[1,2,null,3]]
expected: true
Starter codePython
def same_tree(a, b):
# Your code here
pass5 test cases · run your code against them in the editor