python写算法题:leetcode: 99. Recover Binary Search Tree


class Solution(object):
    def checkOrder(self, node, checkNode, dsc):
        if checkNode[0]!=None: return
        if node==None:
            return
        if dsc:
            self.checkOrder(node.left, checkNode,  dsc)
            if checkNode[0]!=None:
                return
            if checkNode[1]!=None and checkNode[1].val>node.val:
                checkNode[0]=checkNode[1]
                return
            checkNode[1]=node
            self.checkOrder(node.right, checkNode, dsc)
        else:
            self.checkOrder(node.right, checkNode,  dsc)
            if checkNode[0]!=None:
                return
            if checkNode[1]!=None and checkNode[1].val

 

你可能感兴趣的:(算法,python)