guard let root = root else { return true } return checkBound(root, upper: Int.max, lower: Int.min) } } extension Solution { func checkBound(_ root: TreeNode?, upper: Int, lower: Int) -> Bool { guard let root = root else { return true } return root.val < upper && root.val > lower && checkBound(root.left, upper: root.val, lower: lower) && checkBound(root.right, upper: upper, lower: root.val) } } Time Complexity: O(n)
Space Complexity: O(1)
Run Time: 52 ms