Skip to content

Commit

Permalink
Adding solution of Leetcode problem number 98
Browse files Browse the repository at this point in the history
  • Loading branch information
ackerman-mikasa authored Oct 19, 2021
1 parent 0db551f commit 93ad969
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions leetcode/98.Validate_Binary_Search_Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode* root) {
return check(root,LONG_MIN,LONG_MAX);
}
bool check(TreeNode* root,long min,long max)
{
if(!root) return true;
if(root && root->val<=min) return false;
if(root && root->val>=max) return false;
return (check(root->left,min,root->val) && check(root->right,root->val,max) );
}
};

0 comments on commit 93ad969

Please sign in to comment.