Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Validate Binary Search Tree/Validate Binary Search Tree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//leetcode oj 98
//https://leetcode.com/problems/validate-binary-search-tree/description/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool foo(struct TreeNode* root,long int *bar)
{
if(!root)
{
return true;
}
bool _ = foo(root->left,bar);
if(root->val<=*bar)
{
return false;
}
*bar = root->val;
bool __ = foo(root->right,bar);
return _ && __;
}
bool isValidBST(struct TreeNode* root)
{
long int _ = LONG_MIN;
return foo(root,&_);
}