반응형
# 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
class Solution:
def isValidBST(self, root: TreeNode) -> bool:
def isValid(node:TreeNode,low=-math.inf,high=math.inf):
if not node:
return True
else:
if(node.val<=low or node.val>=high):
return False
return isValid(node.left,low,node.val) and isValid(node.right,node.val,high)
return isValid(root)
반응형
'Algorithm > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 100. Same Tree (0) | 2020.12.28 |
---|---|
[LeetCode][Python3] 102. Binary Tree Level Order Traversal (0) | 2020.12.27 |
[LeetCode][Python3] 17. Letter Combinations of a Phone Number (0) | 2020.12.27 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2020.12.26 |
[LeetCode][Python3] 20. Valid Parentheses (0) | 2020.12.26 |