We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Tutorials
  3. Cracking the Coding Interview
  4. Trees: Is This a Binary Search Tree?
  5. Discussions

Trees: Is This a Binary Search Tree?

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • valtheval 4 years ago+ 0 comments

    Hi, I can't see why my solution is wrong, it looks pretty similar. If anyone has an idea...

    def check_binary_search_tree_(root):
        if (root is None):
            return True
        elif (root.left is None) and (root.right is None):
            return -float('inf')<root.data<float('inf')
        elif (root.left is None):
            return (root.right.data>root.data) and check_binary_search_tree_(root.right)
        elif (root.right is None):
            return (root.left.data<root.data) and check_binary_search_tree_(root.left)
        else:
            return (root.left.data<root.data) and (root.right.data>root.data) and check_binary_search_tree_(root.right) and check_binary_search_tree_(root.left)
    
    0|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature