Check if two BSTs contain same set of elements

Given two Binary Search Trees consisting of unique positive elements, we have to check whether the two BSTs contains same set or elements or not.

Note

The structure of the two given BSTs can be different.

We can do inorder traversals of both BST and compare the result.

void BinarySearchTree::inorder(TreeNode *root, vector<int> &result) {
    if (!root) { return; }
    inorder(root->left, result);
    result.push_back(root->val);
    inorder(root->right, result);
}

results matching ""

    No results matching ""