daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     bool isValidBST(TreeNode* root) {
  4.         return CheckIsValidBST(root, numeric_limits<long long>::min(), numeric_limits<long long>::max());
  5.     }
  6.    
  7. private:
  8.     // [min_val, max_val] - valid subtree range
  9.     bool CheckIsValidBST(TreeNode* node, long long min_val, long long max_val) {
  10.         if (!node) return true;
  11.      
  12.         if (node->val <= min_val || node->val >= max_val) return false;
  13.        
  14.         return CheckIsValidBST(node->left, min_val, node->val) && CheckIsValidBST(node->right, node->val, max_val);
  15.     }
  16. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top