To the Top
File:  root - text - article - 2019 - 11 - validate-binary-search-tree.txt.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 148 Views, 13208 Search Bots | 128 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Facebook:

You are given the root of a binary search tree. Return true if it is a valid binary search tree, and false otherwise. Recall that a binary search tree has the property that all values in the left subtree are less than or equal to the root, and all values in the right subtree are greater than or equal to the root.

Here's a starting point:


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

def is_bst(root):
# Fill this in.

a = TreeNode(5)
a.left = TreeNode(3)
a.right = TreeNode(7)
a.left.left = TreeNode(1)
a.left.right = TreeNode(4)
a.right.left = TreeNode(6)
print is_bst(a)

# 5
# / \
# 3 7
# / \ /
#1 4 6
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 148 Views, 13208 Search Bots | 128 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Arithmetic Binary Tree
  2. [Daily Problem] Add two numbers as a linked list
  3. [Daily Problem] Remove k-th Last Element From Linked List
  4. Find Pythagorean Triplets
  5. Daily Interview Problem: Contiguous Subarray with Maximum Sum
  6. Print a tree level-by-level, with line-breaks
  7. Daily Interview Question: Edit Distance
  8. [Daily Problem] Validate Balanced Parentheses
  9. [Daily Problem] Longest Palindromic Substring
  10. First and Last Indices of an Element in a Sorted Array

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />