var isValidBST = function(root) {
//中序遍历排序二叉树必是有序的
let flag = true;
let pre = -Infinity;
const isBst = t =>{
if(t == null)return;
isBst(t.left);
if(t.val <= pre)flag = false;
pre = t.val;
isBst(t.right);
}
isBst(root);
return flag;
};
JS力扣刷题 98. 验证二叉搜索树
最新推荐文章于 2022-06-27 15:39:27 发布