题解 | #牛群中的编号是否有效#
牛群中的编号是否有效
https://www.nowcoder.com/practice/2b4279d545124277a06a8e5eaa802375
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 * @return bool布尔型 */ var flag =true func isValidBST( root *TreeNode ) bool { // write code here if root != nil &&(root.Left!=nil||root.Right!=nil){ if root.Left!=nil{ if root.Left.Val>=root.Val{ flag =false return flag } isValidBST(root.Left) } if root.Right!=nil{ if root.Right.Val<=root.Val{ flag =false return flag } isValidBST(root.Right) } } return flag }