Skip to content

Commit daabfe7

Browse files
committed
Add solution 98.
1 parent 48ed34c commit daabfe7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* class TreeNode {
4+
* public $val = null;
5+
* public $left = null;
6+
* public $right = null;
7+
* function __construct($value) { $this->val = $value; }
8+
* }
9+
*/
10+
class Solution {
11+
12+
/**
13+
* @param TreeNode $root
14+
* @return Boolean
15+
*/
16+
function isValidBST($root) {
17+
return self::helper($root, null, null);
18+
}
19+
20+
function helper($node, $min, $max) {
21+
if ($node == null) return true;
22+
if (($min != null && $node->val <= $min->val) || ($max != null && $node->val >= $max->val)) return false;
23+
return self::helper($node->left, $min, $node) && self::helper($node->right, $node, $max);
24+
}
25+
}

0 commit comments

Comments
 (0)