We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider the case: Only root node, whose value is INT_MAX. The code will output false instead of true.
Solution: Use LLONG_MAX to replace INT_MAX.
class Solution { public: bool isValidBST(TreeNode* root) { return isValidBST(root, LLONG_MIN, LLONG_MAX); } bool isValidBST(TreeNode* root, long long lower, long long upper) { if (!root) return true; return root->val > lower && root->val < upper && isValidBST(root->left, lower, root->val) && isValidBST(root->right, root->val, upper); } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Consider the case: Only root node, whose value is INT_MAX. The code will output false instead of true.
Solution: Use LLONG_MAX to replace INT_MAX.
class Solution {
public:
bool isValidBST(TreeNode* root) {
return isValidBST(root, LLONG_MIN, LLONG_MAX);
}
bool isValidBST(TreeNode* root, long long lower, long long upper) {
if (!root) return true;
return root->val > lower && root->val < upper
&& isValidBST(root->left, lower, root->val)
&& isValidBST(root->right, root->val, upper);
}
};
The text was updated successfully, but these errors were encountered: