目录:
检查一棵二叉树是否为二叉查找树。
http://www.nowcoder.com/practice/536c0199151245f897da2c5390930657?tpId=8&tqId=11015&rp=2&ru=/ta/cracking-the-coding-interview&qru=/ta/cracking-the-coding-interview/question-ranking
思路跟“求BST的第k个结点” 是一样的!! 返回类型不一样! 其他基本都一样!
class Checker {
public:
int last = 0x80000000;
bool checkBST(TreeNode* root) {
// write code here
if(root == NULL)
return true;
bool ret = checkBST(root->left);
if( !ret) return ret;
if(root->val < last)
return false;
else
last = root->val;
ret = checkBST(root->right);
if( !ret) return ret;