Python Solution using inorder traversal beats 81% of submissions


  • 1
    N

    ''' '''

    def getMinimumDifference(self, root):

       if root is None:
            return 
        
        temp=[]
        node = self.inorder(root,temp)
        temp2 = min([abs(node[i+1] - node[i]) for i in range(len(node)-1)])
        return temp2
            
    def inorder(self,root,temp):
        if root == None:
            return 
        self.inorder(root.left,temp)
        temp.append(root.val)
        
        self.inorder(root.right,temp)
        return temp'''

Log in to reply
 

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