-
98. Validate Binary Search TreeAlgorithm/java tip 2021. 3. 14. 17:32
leetcode.com/problems/validate-binary-search-tree/
Validate Binary Search Tree - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution { public boolean isValidBST(TreeNode root) { return isValidBST(root, false, false, 0, 0); } public boolean isValidBST(TreeNode root, boolean isLower, boolean isUpper, int lower, int upper) { if(root == null) return true; // 현재 노두가 lower/upper 를 침범하지 않는가 if(isLower && root.val <= lower) { return false; } if(isUpper && root.val >= upper) { return false; } return isValidBST(root.left, isLower, true, lower, root.val) && isValidBST(root.right, true, isUpper, root.val, upper); } }
Learn one iterative inorder traversal, apply it to multiple tree questions (Java Solution) - LeetCode Discuss
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'Algorithm > java tip' 카테고리의 다른 글
1557. Minimum Number of Vertices to Reach All Nodes (0) 2021.03.20 797. All Paths From Source to Target (0) 2021.03.20 21. Merge Two Sorted Lists (0) 2021.03.13 530. Minimum Absolute Difference in BST (0) 2021.03.13 589. N-ary Tree Preorder Traversal (0) 2021.03.13