Find inorder sucessor for a input value

class TreeNode(object):
    def __init__(self,value):
        self.value = value
        self.left = None
        self.right = None

    def __repr__(self):
        return str(self.value)
class Solution(object):
    def find_next_max_node(root,k):
        if not root:
            return None
        first_so_far = None
        while root:
            if root.data > k:
                first_so_far = root
                root = root.left
            else:
                root = root.right

        return first_so_far

Time complexity O(h) height of tree

results matching ""

    No results matching ""