https://leetcode.com/problems/validate-binary-search-tree


Runtime: 1336 ms, faster than 5.21% of Python3 online submissions for Validate Binary Search Tree.
Memory Usage: 17.3 MB, less than 7.47% of Python3 online submissions for Validate Binary Search Tree.


```python
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right

def travel_to_get_all_values(node: TreeNode):
    if (node != None):
        l = [node.val]
        if (node.left != None):
            l.append(node.left.val)
        if (node.right != None):
            l.append(node.right.val)
        return travel_to_get_all_values(node.left) + travel_to_get_all_values(node.right) + l
    else:
        return []
        
        
not_valid = False

def travel(node: TreeNode):
    global not_valid
    
    if (not_valid == True):
        return
    
    if node != None:
        """
        if (node.left != None and node.right != None):
            if (node.left.val < node.val < node.right.val):
                #not_valid = False
                pass
            else:
                not_valid = True
        if (node.left != None):
            if (node.left.val < node.val):
                pass
            else:
                not_valid = True
        if (node.right != None):
            if (node.val < node.right.val):
                pass
            else:
                not_valid = True
        """
        left_list = travel_to_get_all_values(node.left)
        right_list = travel_to_get_all_values(node.right)
        
        if (len(left_list) > 0):
            if (max(left_list) < node.val):
                pass
            else:
                not_valid = True
        
        if (len(right_list) > 0):
            if (min(right_list) > node.val):
                pass
            else:
                not_valid = True
                
        travel(node.left)
        travel(node.right)
        
class Solution:
    def isValidBST(self, root: TreeNode) -> bool:
        #6:30
        global not_valid
        not_valid = False
        travel(root)
        return not not_valid
        #6:35
        #debug and continue development until 6:57
```