标签:bool ali validate bst style arch for sea als
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool isValidBST(TreeNode* root) { return isValidBST(root, NULL, NULL); } bool isValidBST(TreeNode* root, TreeNode* _min, TreeNode* _max) { if (root == NULL) return true; if (_min != NULL && root->val <= _min->val || _max != NULL && root->val >= _max->val) return false; return isValidBST(root->left, _min, root) && isValidBST(root->right, root, _max); } };
98. Validate Binary Search Tree
标签:bool ali validate bst style arch for sea als
原文地址:https://www.cnblogs.com/JTechRoad/p/9063179.html