Python fast iterative

  • 0
    class Solution(object):
        def getMinimumDifference(self, root):
            :type root: TreeNode
            :rtype: int
            stack = []
            current = root
            last = None
            minVal = float('inf')
            while stack or current:
                if current: 
                    current = current.left
                    node = stack.pop()
                    current = node.right
                    if not last is None:
                        minVal = min(minVal, node.val - last)
                    last = node.val
            return minVal

Log in to reply

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