Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
629 B
1
Indexable
Never
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def getMinimumDifference(self, root: Optional[TreeNode]) -> int:
        
        def trvl(root,prev,mi):
            if root==None:
                return 10000000
            else:
                if mi>abs(prev-root.val):
                    mi=abs(prev-root.val)
                return mi
            return min(trvl(root.left,root.val,mi),trvl(root.right,root.val,mi))
        return trvl(root,root.val,10000000)