You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
funisValidBST(root:TreeNode): Boolean {
return dfs(root, Long.MIN_VALUE, Long.MAX_VALUE)
}
fundfs(node:TreeNode?, mini:Long, maxi:Long): Boolean {
if (node ==null) returntrue// node must in range of current path's min and max values.if (node.`val` >= maxi || node.`val` <= mini) returnfalse// left subtree's : min = given min, max = current node's value.// right subtree's : min = current node's value, max = given maxreturn dfs(node.left, mini, node.`val`.toLong()) && dfs(node.right, node.`val`.toLong(), maxi)
}
}