void inorder(struct TreeNode* root, int* a, int* i)
{
if (root == NULL)
{
return;
}
if (root != NULL)
{
inorder(root->left, a, i);
a[*i] = root->val;
*i += 1;
inorder(root->right, a, i);
}
}
bool isValidBST(struct TreeNode* root)
{
int i = 0;
int* a = malloc(10000 * sizeof(int));
inorder(root, a, &i);
for (int j = 0; j < i - 1; j++)
{
if (a[j] >= a[j + 1])
{
return false;
}
}
return true;
}
98. 验证二叉搜索树
最新推荐文章于 2024-11-15 16:27:37 发布