Description:
Solution:
In helper(), we are gonna update the boundary to check the val is satisfied in boundary condition.
min_val is the left boundary.
max_val is the right boundary.
helper() return the new boundary.
"-2**31-1" and "2**31" are the initial value for the root value.
It represents "-∞ <" and "< ∞"
In the example 2:
5 -> -∞, ∞
1 -> -∞, 5 (satisfied)
4 -> 5, ∞ (not satisfied) -> return False
Time Complexity: O(N)
'LeetCode ๐๏ธ > Tree' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
230. Kth Smallest Element in a BST (0) | 2023.06.05 |
---|---|
297. Serialize and Deserialize Binary Tree (0) | 2023.06.04 |
105. Construct Binary Tree from Preorder and Inorder Traversal (0) | 2023.06.02 |
572. Subtree of Another Tree (0) | 2023.04.02 |
102. Binary Tree Level Order Traversal (0) | 2023.03.21 |