Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
- public class Solution {
- public bool IsValidBST(TreeNode root) {
- int? current = null;
- return IsValidBST(root, ref current);
- }
- public bool IsValidBST(TreeNode node, ref int? current)
- {
- if(node == null)
- return true;
- if(!IsValidBST(node.left, ref current))
- return false;
- if(current >= node.val)
- return false;
- current = node.val;
- if(!IsValidBST(node.right, ref current))
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement