Finding the largest subtree in a BST
问题 Given a binary tree, I want to find out the largest subtree which is a BST in it. Naive approach: I have a naive approach in mind where I visit every node of the tree and pass this node to a isBST function. I will also keep track of the number of nodes in a sub-tree if it is a BST. Is there a better approach than this ? 回答1: I have posted the full solution and explanation in my blog: http://www.leetcode.com/2010/11/largest-binary-search-tree-bst-in.html The idea is to do a depth-first