Is This a Binary Search Tree?

Sort by

recency

|

896 Discussions

|

  • + 0 comments
    def check_binary_search_tree_(root):
        # create helper function
        def check(root, min_value, max_value):
            # base case
            if root is None:
                return True
            
            # general case
            if root.data < min_value or root.data > max_value:
                return False
            
            return check(root.left, min_value, root.data - 1) and check(root.right, root.data + 1, max_value)
        
        return check(root, 0, 10000)
    
  • + 1 comment
    def inorder_list(root):
        values = []
        def inorder_t(root):
            if root is None:
                return
            inorder_t(root.left)
            values.append(root.data)
            inorder_t(root.right)
        inorder_t(root)
        return values
    
    def check_binary_search_tree_(root):
        if root is None:
            return
        values = inorder_list(root)
        if values == sorted(values) and len(values) == len(set(values)):
            return True
        else:
            return False
    
  • + 0 comments

    Java8: Could not find or load main class Solution Java7: passed all tests successfully

  • + 0 comments

    Very poor problem description. How should I know what's the input and what's the class structure for a Node? I am getting continiously - Node is not a valid...

  • + 1 comment

    Getting error ...saying can't find Solution class