You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each node is responsible of telling its parent if it is deleting, by returning itself. We do the check after iteration, to respect the constraint that new leaves can be cut as well.
"""
class Solution:
def solve(self, root):
def dfs(node):
if not node: return None
node.left=dfs(node.left)
node.right=dfs(node.right)
if not node.left and not node.right and not node.val&1: return None