int main()
{
	srand(time(NULL));
	RandomizedSet obj;
	cout << obj.insert(1) << endl;
	cout << obj.insert(1) << endl;
	cout << obj.insert(2) << endl;
	cout << obj.remove(2) << endl;
	cout << obj.getRandom() << endl;
}
int main(){
    
    RandomizedSet set;
    cout<<set.getRandom()<<endl;
    cout<<set.insert(1)<<endl;
    cout<<set.remove(2)<<endl;
    cout<<set.insert(2)<<endl;
    cout<<set.getRandom()<<endl;
    cout<<set.remove(1)<<endl;
    cout<<set.insert(2)<<endl;
    cout<<set.getRandom()<<endl;
    
    return 0;
}
示例#3
0
/**
 * Your RandomizedSet object will be instantiated and called as such:
 * RandomizedSet obj = new RandomizedSet();
 * bool param_1 = obj.insert(val);
 * bool param_2 = obj.remove(val);
 * int param_3 = obj.getRandom();
 */
int main () {
    RandomizedSet* obj = new RandomizedSet();
    std::cout << obj->remove(0) << std::endl;
    std::cout << obj->remove(0) << std::endl;
    std::cout << obj->insert(0) << std::endl;
    std::cout << obj->getRandom() << std::endl;
    std::cout << obj->remove(0) << std::endl;
    std::cout << obj->insert(0) << std::endl;
    return 0;
}
 void test() {
     RandomizedSet randomSet;
     cout << randomSet.insert(1) << endl;
     cout << randomSet.insert(1) << endl;
     cout << randomSet.remove(2) << endl;
     cout << randomSet.insert(2) << endl;
     cout << "1 1 2" << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << "===" << endl;
     cout << randomSet.remove(1) << endl;
     cout << randomSet.insert(2) << endl;
     cout << "1 2 2" << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
     cout << randomSet.getRandom() << endl;
 }