/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param root TreeNode类 
 * @return bool布尔型
 */
function isValidBST( root ) {
    // write code here
    const res = [];
    // 中序遍历
    midOrder(root, res);
    // 判断数组是否是递增的
    for(let i=0; i<res.length-1; i++) {
        if(res[i]>res[i+1]) {
            return false;
        }
    }
    return true;
}
function midOrder(root, arr) {
    if(!root) return;
    midOrder(root.left, arr);
    arr.push(root.val);
    midOrder(root.right, arr);
}
module.exports = {
    isValidBST : isValidBST
};