BST는 Inorder Traversal 을 수행하며 키를 순서대로 가져올 수 있다
leetcode 문제에선 해당 트리가 BST를 만족하는지 물었다
var isValidBST = function(root) {
if(!root){
return true;
}
function helper(root, min, max){
if(!root) return true;
if((min !== null && min>= root.val) || (max !== null && max <= root.val)){
console.log('1')
return false;
}
return helper(root.left, min, root.val) && helper(root.right, root.val, max);
}
return helper(root, null, null);
};