Created
July 2, 2020 07:46
-
-
Save alldroll/eb7eb5886abb5884be63bbca585e3022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Definition for a binary tree node. | |
| * type TreeNode struct { | |
| * Val int | |
| * Left *TreeNode | |
| * Right *TreeNode | |
| * } | |
| */ | |
| func isValidBST(root *TreeNode) bool { | |
| return checkIsValid(root, -1 << 32, (1 << 32) - 1) | |
| } | |
| func checkIsValid(root *TreeNode, from, to int) bool { | |
| if root == nil { | |
| return true | |
| } | |
| if root.Val <= from || root.Val >= to { | |
| return false | |
| } | |
| return checkIsValid(root.Left, from, root.Val) && checkIsValid(root.Right, root.Val, to) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment