📜  检查有效的二叉搜索树 java - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:48.243000             🧑  作者: Mango

代码示例1
public bool IsBinaryTree(Node node, int min = int.MinValue, int max = int.MaxValue)
{
    if (root == null)
        return true;
    if (node.data < min || node.data > max)
        return false;
        
    return  IsBinaryTree(node.leftChild,min,node.data-1) &&
            IsBinaryTree(node.rightChild,node.data+1,max);
}

// node Structure
    public class Node
    {
        public int data;
        public Node leftChild;
        public Node rightChild;
        public Node(int data)
        {
            this.data = data;
        }
    }