Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb572df8

Browse files
authored
Merge pull requestneetcode-gh#1037 from julienChemillier/patch-6
Add 98 in c language
2 parentsedcdf10 +49aaf9d commitb572df8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎c/98-Validate-Binary-Search-Tree.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
3+
Time: O(n)
4+
Space: O(1)
5+
*/
6+
7+
#defineMAX 9223372036854775807
8+
#defineMIN -9223372036854775808
9+
10+
boolisSubTreeValid(structTreeNode*root,longintlowerBound,longintupperBound) {
11+
if (root==NULL)
12+
return true;
13+
returnroot->val<upperBound&&root->val>lowerBound&&isSubTreeValid(root->left,lowerBound,root->val)&&isSubTreeValid(root->right,root->val,upperBound);
14+
}
15+
16+
boolisValidBST(structTreeNode*root){
17+
returnisSubTreeValid(root,MIN,MAX);
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp