首页 > 其他 > 详细

[Locked] Largest BST Subtree

时间:2016-02-27 23:21:16      阅读:284      评论:0      收藏:0      [点我收藏+]

Largest BST Subtree

Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.

Note:
A subtree must include all of its descendants.
Here‘s an example:

    10
    /    5  15
  / \   \ 
 1   8   7

The Largest BST Subtree in this case is the highlighted one. 
The return value is the subtree‘s size, which is 3.

    Follow up:
    Can you figure out ways to solve it with O(n) time complexity?

    [Locked] Largest BST Subtree

    原文:http://www.cnblogs.com/littletail/p/5222460.html

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
    © 2014 bubuko.com 版权所有
    打开技术之扣,分享程序人生!