Minimum Absolute Difference in BST (Leetcode 530)
Hint: The answer is same as Leetcode 783
Problem Link: https://leetcode.com/problems/minimum-absolute-difference-in-bst/
class Solution:
def getMinimumDifference(self, root: Optional[TreeNode]) -> int:
global ans,prev
ans=float('inf')
prev=float('-inf')
def fun(root):
global ans
global prev
if(root is None):
return None
fun(root.left)
ans=min(ans,root.val-prev)
prev=root.val
fun(root.right)
fun(root)
return ans
PreviousMinimum Distance Between BST Nodes (Leetcode 783)NextCousins in a Binary Tree (Leetcode 993)
Last updated