bool isDUI(TreeNode* root)
{
if (root == NULL)
return true;
bool l = false;
bool r = false;
l = isDUI(root->left);
r = isDUI(root->right);
bool isOK = true;
if (root->left != NULL)
isOK = isOK && (root->left->val < root->val);
if (root->right != NULL)
isOK = isOK && (root->right->val > root->val);
if (l&&r&&isOK)
return true;
else
return false;
}
树的所有左节点小于根节点,所有右节点大于根节点(不是二叉搜索树)
最新推荐文章于 2024-03-05 12:17:05 发布