0
点赞
收藏
分享

微信扫一扫

98. 验证二叉搜索树

攻城狮Chova 2022-01-24 阅读 54
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;
}
举报

相关推荐

0 条评论