天天看点

333. Largest BST Subtree

333. largest bst subtree

i feel this is post order traversal 

​​https://www.youtube.com/watch?v=4fids7ccxkc​​

​​https://leetcode.com/problems/largest-bst-subtree/discuss/78891/share-my-o(n)-java-code-with-brief-explanation-and-comments​​

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.

example:

follow up:

can you figure out ways to solve it with o(n) time complexity?

继续阅读