验证二叉搜索树 leetcode 98

根据二叉搜索树性质验证:中序遍历序列有序

class Solution {
public:
    long tmp = LONG_MIN;
    bool isValidBST(TreeNode* root) {
        if(root == nullptr) return true;
        if (isValidBST(root->left)) {
            if (tmp < root->val) {
                tmp = root->val;
                return isValidBST(root->right);
            }
        }
        return false;
   }
};

你可能感兴趣的:(【算法,&,数据结构】)