欧美1区2区3区激情无套,两个女人互添下身视频在线观看,久久av无码精品人妻系列,久久精品噜噜噜成人,末发育娇小性色xxxx

題解 | #判斷是不是二叉搜索樹#

判斷是不是二叉搜索樹

http://fangfengwang8.cn/practice/a69242b39baf45dea217815c7dedb52b

/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */
/**
 * 代碼中的類名、方法名、參數(shù)名已經(jīng)指定,請勿修改,直接返回方法規(guī)定的值即可
 *
 * 
 * @param root TreeNode類 
 * @return bool布爾型
 */
function isValidBST( root ) {
    // write code here
    console.log(root)
    if (root === null) {
        return true
    }
    if (!root.left && !root.right) {
        return true
    }
    let left = root.left === null? -Infinity : root.left.val
    let right = root.right === null? Infinity : root.right.val
    let left_right = root.left.right === null? -Infinity : root.left.right.val
    if ((left < root.val) && (root.val< right) && (left_right < root.val)) {
        return isValidBST(root.left) && isValidBST(root.right)
    }
    else {
        return false
    }
}
module.exports = {
    isValidBST : isValidBST
};

全部評論

相關(guān)推薦

04-06 11:24
已編輯
太原學(xué)院 C++
點贊 評論 收藏
分享
評論
點贊
收藏
分享

創(chuàng)作者周榜

更多
??途W(wǎng)
??推髽I(yè)服務(wù)