Given 2 binary expression trees tree1 and tree2. The leaves of a binary expression tree are variable names and the other nodes contain operators. Find out if the expressions represented by these trees are equal or not.
There are only plus signs + and letters in the tree. Input is guaranteed to be valid.
Example 1:
Input:
tree1
+
/ \
a b
tree2
+
/ \
b a
Output: true
Explanation: a + b = b + aExample 2:
Input:
tree1
+
/ \
a +
/ \
c de
tree2
+
/ \
+ de
/ \
a c
Output: true
Explanation: a + (c + de) == (a + c) + deExample 3:
Input:
tree1
+
/ \
a b
tree2
+
/ \
c d
Output: false
Explanation: a + b != c + dFollow-up:
Minus - sign is allowed. For example
+
/ \
a -
/ \
c d
a + (c - d)