Python Solution


  • 0
    def findTilt(self, root):
            tot=[]
            def inTrav(node):
                if node is None: return 0
                x,y=inTrav(node.left),inTrav(node.right)
                tot.append(abs(x-y))
                return x+y+node.val
            if root is None: return 0
            tot.append(abs(inTrav(root.left)-inTrav(root.right)))
            return sum(tot)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.