I originally thought that for getRandom, as long as the probability is the same, it’s fine. However, this problem’s test likely sets a random seed. If you don’t call rand(), the order will definitely differ from the answer. This problem mainly uses a hashmap to store val, index, and a vector for random access. When inserting, directly put it at the end of the vector. When deleting, swap the element to be deleted with the last element, then pop_back(). Remember to update the index of the last element in the hashmap due to the swap.