Created
May 12, 2015 03:16
-
-
Save sanketfirodiya/eabdc41003545f84ca75 to your computer and use it in GitHub Desktop.
Check if BST is valid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (BOOL)isBSTValid { | |
return [self validate:self.root withMin:MIN.INTEGER withMax:MAX.INTEGER]; | |
} | |
- (BOOL)validate:(Node *)root withMin:(NSUInteger)min withMax:(NSUInteger)max { | |
if (root.value <= min || root.value >= max) { | |
return NO; | |
} | |
return ([self validate:root.left withMin:min withMax:root.Value] && [self validate:root.right withMin:root.value withMax:max]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment