I am new to navigating Binary Tree's. I was able to eventually figure out a solution to this problem looking through some of the answers in the discussion.
I am still not sure why I was not able get this code to work. I think there is something about the nodes that I do not understand. They are not iterable?
I also attempted to work throught the solution by using a hash map then a try, except and appending to a list that would return the answer.
Please let me know what I am missing.
class Solution:
def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:
if not root:
return []
a = []
b = []
def fr(root):
if not root: return
if root in a:
b.append(root)
else:
a.append(root)
fr(root.left)
fr(root.right)
fr(root)
return b