Same tree
You get the roots p and q of two binary trees. Return True if they are the same tree and False if not. Two trees are the same when they have the same shape and every pair of nodes in matching positions holds equal values. Two empty trees (None and None) are the same.
Trees in the examples are written in level order, the way build_tree reads them: the root, then each row from left to right, with None where a child is missing.
p = [5, 3, 8, 1], q = [5, 3, 8, 1]OutputTrueSame shape, same value in every position.
p = [5, 3], q = [5, None, 3]OutputFalseSame values, different shape: 3 is a left child in p and a right child in q.
p = [5, 3, 8], q = [5, 8, 3]OutputFalseSame shape, but the two children hold different values.
0 ≤ number of nodes in each tree ≤ 100
-104 ≤ node values ≤ 104
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.