【LeetCode热题100(43/100)】验证二叉搜索树
题目地址:链接
思路: 中序遍历
/*** Definition for a binary tree node.* function TreeNode(val, left, right) {* this.val = (val===undefined ? 0 : val)* this.left = (left===undefined ? null : left)* this.right = (right===undefined ? null : right)* }*/
/*** @param {TreeNode} root* @return {boolean}*/
var isValidBST = function(root) {const dfs = (root, left, right) => {if(!root) return true;return root.val > left && root.val < right &&dfs(root.left, left, root.val) &&dfs(root.right, root.val, right);}return dfs(root, -Infinity, Infinity);
};